NeMo
PyTorch
nemotron
srvm commited on
Commit
91968f6
·
1 Parent(s): d9660bf

Update README

Browse files
Files changed (1) hide show
  1. README.md +12 -9
README.md CHANGED
@@ -30,22 +30,25 @@ import torch
30
  from transformers import AutoTokenizer, AutoModelForCausalLM
31
 
32
  # Load the tokenizer and model
33
- model_path = "nvidia/Minitron-4B-Base"
34
- tokenizer = AutoTokenizer.from_pretrained(model_path)
35
 
36
- device='cuda'
37
- dtype=torch.bfloat16
38
- model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=dtype, device_map=device)
39
 
40
  # Prepare the input text
41
- prompt = "To be or not to be,"
42
- input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
43
 
44
  # Generate the output
45
- output_ids = model.generate(input_ids, max_length=50, num_return_sequences=1)
 
 
 
46
 
47
  # Decode and print the output
48
- output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
49
  print(output_text)
50
  ```
51
 
 
30
  from transformers import AutoTokenizer, AutoModelForCausalLM
31
 
32
  # Load the tokenizer and model
33
+ model_path = 'nvidia/Minitron-4B-Base'
34
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
35
 
36
+ device = 'cuda'
37
+ dtype = torch.bfloat16
38
+ model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=dtype, device_map=device)
39
 
40
  # Prepare the input text
41
+ prompt = 'Complete the paragraph: our solar system is'
42
+ inputs = tokenizer.encode(prompt, return_tensors='pt').to(model.device)
43
 
44
  # Generate the output
45
+ outputs = model.generate(inputs,
46
+ max_length=20,
47
+ num_return_sequences=1,
48
+ pad_token_id=tokenizer.eos_token_id)
49
 
50
  # Decode and print the output
51
+ output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
52
  print(output_text)
53
  ```
54