Update README.md
Browse files
README.md
CHANGED
@@ -34,12 +34,17 @@ Gemma-2B Fine-Tuned Python Model is a deep learning model based on the Gemma-2B
|
|
34 |
1. **Install Gemma Python Package**:
|
35 |
```bash
|
36 |
pip install -q -U transformers==4.38.0
|
|
|
37 |
```
|
38 |
|
39 |
## Inference
|
|
|
40 |
1. **How to use the model in our notebook**:
|
41 |
```python
|
|
|
|
|
42 |
# Load model directly
|
|
|
43 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
44 |
|
45 |
tokenizer = AutoTokenizer.from_pretrained("suriya7/Gemma-2B-Finetuned-Python-Model")
|
@@ -51,12 +56,15 @@ prompt_template = f"""
|
|
51 |
<end_of_turn>\n<start_of_turn>model
|
52 |
"""
|
53 |
prompt = prompt_template
|
54 |
-
encodeds = tokenizer(prompt, return_tensors="pt", add_special_tokens=True)
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
model_inputs = encodeds.to('cuda')
|
57 |
|
58 |
# Increase max_new_tokens if needed
|
59 |
-
generated_ids = model.generate(
|
60 |
ans = ''
|
61 |
for i in tokenizer.decode(generated_ids[0], skip_special_tokens=True).split('<end_of_turn>')[:2]:
|
62 |
ans += i
|
|
|
34 |
1. **Install Gemma Python Package**:
|
35 |
```bash
|
36 |
pip install -q -U transformers==4.38.0
|
37 |
+
pip install torch
|
38 |
```
|
39 |
|
40 |
## Inference
|
41 |
+
|
42 |
1. **How to use the model in our notebook**:
|
43 |
```python
|
44 |
+
|
45 |
+
|
46 |
# Load model directly
|
47 |
+
import torch
|
48 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
49 |
|
50 |
tokenizer = AutoTokenizer.from_pretrained("suriya7/Gemma-2B-Finetuned-Python-Model")
|
|
|
56 |
<end_of_turn>\n<start_of_turn>model
|
57 |
"""
|
58 |
prompt = prompt_template
|
59 |
+
encodeds = tokenizer(prompt, return_tensors="pt", add_special_tokens=True).input_ids
|
60 |
+
|
61 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
62 |
+
model.to(device)
|
63 |
+
inputs = encodeds.to(device)
|
64 |
|
|
|
65 |
|
66 |
# Increase max_new_tokens if needed
|
67 |
+
generated_ids = model.generate(inputs, max_new_tokens=1000, do_sample=False, pad_token_id=tokenizer.eos_token_id)
|
68 |
ans = ''
|
69 |
for i in tokenizer.decode(generated_ids[0], skip_special_tokens=True).split('<end_of_turn>')[:2]:
|
70 |
ans += i
|