Spaces:
Running
Running
messy code
#1
by
sqrt81 - opened
README.md
CHANGED
|
@@ -58,61 +58,6 @@ inputs = tokenizer(text, return_tensors="pt")
|
|
| 58 |
outputs = model(**inputs)
|
| 59 |
```
|
| 60 |
|
| 61 |
-
OR
|
| 62 |
-
|
| 63 |
-
```python
|
| 64 |
-
from transformers import LlamaForCausalLM, LlamaTokenizer
|
| 65 |
-
import torch
|
| 66 |
-
|
| 67 |
-
# Path to your model directory
|
| 68 |
-
model_path = "MetaTrustSig/13b_reasoner"
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# Load the tokenizer
|
| 72 |
-
tokenizer = LlamaTokenizer.from_pretrained(model_path)
|
| 73 |
-
|
| 74 |
-
# Add special tokens if they are missing
|
| 75 |
-
if tokenizer.eos_token is None:
|
| 76 |
-
tokenizer.add_special_tokens({
|
| 77 |
-
'eos_token': '</s>',
|
| 78 |
-
'bos_token': '<s>',
|
| 79 |
-
'unk_token': '<unk>',
|
| 80 |
-
'pad_token': '<pad>'
|
| 81 |
-
})
|
| 82 |
-
|
| 83 |
-
# Load the model with the language modeling head
|
| 84 |
-
model = LlamaForCausalLM.from_pretrained(model_path)
|
| 85 |
-
model.resize_token_embeddings(len(tokenizer))
|
| 86 |
-
|
| 87 |
-
# Move model to GPU if available
|
| 88 |
-
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 89 |
-
model.to(device)
|
| 90 |
-
|
| 91 |
-
text = "YOUR INPUT"
|
| 92 |
-
|
| 93 |
-
# Tokenize input and move tensors to the appropriate device
|
| 94 |
-
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 95 |
-
|
| 96 |
-
# Generate text
|
| 97 |
-
# You can change the generation config
|
| 98 |
-
generated_outputs = model.generate(
|
| 99 |
-
input_ids=inputs['input_ids'],
|
| 100 |
-
attention_mask=inputs['attention_mask'],
|
| 101 |
-
max_length=1024,
|
| 102 |
-
do_sample=True,
|
| 103 |
-
temperature=0.2,
|
| 104 |
-
top_p=0.9,
|
| 105 |
-
repetition_penalty=1.1,
|
| 106 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
-
# Decode the output
|
| 110 |
-
generated_text = tokenizer.decode(generated_outputs[0], skip_special_tokens=True)
|
| 111 |
-
|
| 112 |
-
print(generated_text)
|
| 113 |
-
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
## Contributing
|
| 117 |
|
| 118 |
Contributions to Marvinmw/{13b,34b}_reasoner are welcome! Here's how you can contribute:
|
|
|
|
| 58 |
outputs = model(**inputs)
|
| 59 |
```
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
## Contributing
|
| 62 |
|
| 63 |
Contributions to Marvinmw/{13b,34b}_reasoner are welcome! Here's how you can contribute:
|