Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_name = "alexchen4ai/Qwen3-8B-Instruct"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype=torch.bfloat16,
10 device_map="auto"
11)
12
13messages = [
14 {"role": "system", "content": "You are a helpful assistant."},
15 {"role": "user", "content": "What is the capital of France?"}
16]
17
18text = tokenizer.apply_chat_template(
19 messages,
20 tokenize=False,
21 add_generation_prompt=True
22)
23
24inputs = tokenizer([text], return_tensors="pt").to(model.device)
25
26outputs = model.generate(
27 **inputs,
28 max_new_tokens=512,
29 temperature=0.7,
30 top_p=0.9,
31 do_sample=True
32)
33
34response = tokenizer.decode(outputs[0], skip_special_tokens=True)
35print(response)model.language_model.* weightsmodel.*)lm_head for token predictionmodel.visual.*)1@article{qwen3vl,
2 title={Qwen3-VL: Towards Versatile Vision-Language Understanding},
3 author={Qwen Team},
4 year={2024}
5}