Update README.md
Browse files
README.md
CHANGED
|
@@ -36,27 +36,29 @@ pip install -U transformers accelerate
|
|
| 36 |
Here is a simple example demonstrating how to load the model and generate code using the Hugging Face `pipeline` API:
|
| 37 |
|
| 38 |
```python
|
| 39 |
-
|
| 40 |
import torch
|
| 41 |
|
| 42 |
model_id = "ByteDance-Seed/Seed-Coder-8B-Instruct"
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
model=model_id,
|
| 47 |
-
model_kwargs={"torch_dtype": torch.bfloat16},
|
| 48 |
-
device_map="auto",
|
| 49 |
-
)
|
| 50 |
|
| 51 |
messages = [
|
| 52 |
{"role": "user", "content": "Write a quick sort algorithm."},
|
| 53 |
]
|
| 54 |
|
| 55 |
-
|
| 56 |
messages,
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
## Evaluation
|
|
|
|
| 36 |
Here is a simple example demonstrating how to load the model and generate code using the Hugging Face `pipeline` API:
|
| 37 |
|
| 38 |
```python
|
| 39 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 40 |
import torch
|
| 41 |
|
| 42 |
model_id = "ByteDance-Seed/Seed-Coder-8B-Instruct"
|
| 43 |
|
| 44 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 45 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
messages = [
|
| 48 |
{"role": "user", "content": "Write a quick sort algorithm."},
|
| 49 |
]
|
| 50 |
|
| 51 |
+
input_ids = tokenizer.apply_chat_template(
|
| 52 |
messages,
|
| 53 |
+
tokenize=True,
|
| 54 |
+
return_tensors="pt",
|
| 55 |
+
add_generation_prompt=True,
|
| 56 |
+
).to(model.device)
|
| 57 |
+
|
| 58 |
+
outputs = model.generate(input_ids, max_new_tokens=512)
|
| 59 |
+
response = tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True)
|
| 60 |
+
print(response)
|
| 61 |
+
|
| 62 |
```
|
| 63 |
|
| 64 |
## Evaluation
|