Views
No views yet
[!CAUTION] For optimal performance, we refrain from fine-tuning the model's identity. Thus, inquiries such as "Who are you" or "Who developed you" may yield random responses that are not necessarily accurate.
transformers package to ensure it supports Llama3.1 models. The current version we are using is 4.43.0.1from huggingface_hub import snapshot_download
2snapshot_download(repo_id="shenzhi-wang/Llama3.1-8B-Chinese-Chat", ignore_patterns=["*.gguf"]) # Download our BF16 model without downloading GGUF models.1import torch
2import transformers
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5model_id = "/Your/Local/Path/to/Llama3.1-8B-Chinese-Chat"
6dtype = torch.bfloat16
7
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 device_map="cuda",
12 torch_dtype=dtype,
13)
14
15chat = [
16 {"role": "user", "content": "写一首关于机器学习的诗。"},
17]
18input_ids = tokenizer.apply_chat_template(
19 chat, tokenize=True, add_generation_prompt=True, return_tensors="pt"
20).to(model.device)
21
22outputs = model.generate(
23 input_ids,
24 max_new_tokens=8192,
25 do_sample=True,
26 temperature=0.6,
27 top_p=0.9,
28)
29response = outputs[0][input_ids.shape[-1] :]
30print(tokenizer.decode(response, skip_special_tokens=True))