Views
No views yet
1!pip install -q -U trl transformers accelerate git+https://github.com/huggingface/peft.git
2!pip install -q datasets bitsandbytes einops wandb sentencepiece transformers_stream_generator tiktoken
3
4from transformers import AutoModelForCausalLM, AutoTokenizer
5import torch
6
7tokenizer = AutoTokenizer.from_pretrained("TinyPixel/qwen-1.8B-OrcaMini", trust_remote_code=True)
8model = AutoModelForCausalLM.from_pretrained("TinyPixel/qwen-1.8B-OrcaMini", torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
9
10device = "cuda:0"
11
12text = '''SYSTEM:
13USER: what is the difference between a dog and a cat on a biological level?
14ASSISTANT:'''
15
16inputs = tokenizer(text, return_tensors="pt").to(device)
17outputs = model.generate(**inputs,
18 max_new_tokens=512,
19 do_sample=True,
20 top_p=0.95,
21 temperature=0.7,
22 top_k=50)
23
24print(tokenizer.decode(outputs[0], skip_special_tokens=False))