kmamaroziqov commited on
Commit
569f809
·
verified ·
1 Parent(s): 09201e8

Fix inference example and multi-GPU device placement

Browse files
Files changed (1) hide show
  1. README.md +14 -7
README.md CHANGED
@@ -56,12 +56,14 @@ import torch
56
  from transformers import AutoModelForCausalLM, AutoTokenizer
57
 
58
  model_id = "NeuronUz/qwen3.5-2b-fine-tuned"
 
59
 
60
  tokenizer = AutoTokenizer.from_pretrained(model_id)
61
  model = AutoModelForCausalLM.from_pretrained(
62
  model_id,
63
  torch_dtype="auto",
64
- device_map="auto",
 
65
  )
66
 
67
  messages = [
@@ -73,26 +75,31 @@ inputs = tokenizer.apply_chat_template(
73
  messages,
74
  add_generation_prompt=True,
75
  return_tensors="pt",
 
76
  ).to(model.device)
77
 
78
  with torch.inference_mode():
79
  output = model.generate(
80
- inputs,
81
  max_new_tokens=256,
82
- do_sample=True,
83
- temperature=0.7,
84
- top_p=0.9,
85
  )
86
 
87
- print(tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True))
 
88
  ```
89
 
90
  Use a recent Transformers release with Qwen3.5 support.
91
 
 
 
 
 
 
 
92
  ## Limitations
93
 
94
  The model may produce inaccurate, biased, or fabricated information. It has not
95
  been comprehensively evaluated for safety or high-stakes domains. Outputs should
96
  be independently verified before use in medical, legal, financial, or other
97
  consequential settings.
98
-
 
56
  from transformers import AutoModelForCausalLM, AutoTokenizer
57
 
58
  model_id = "NeuronUz/qwen3.5-2b-fine-tuned"
59
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
60
 
61
  tokenizer = AutoTokenizer.from_pretrained(model_id)
62
  model = AutoModelForCausalLM.from_pretrained(
63
  model_id,
64
  torch_dtype="auto",
65
+ # Keep this hybrid model on one device. See the note below.
66
+ device_map=device,
67
  )
68
 
69
  messages = [
 
75
  messages,
76
  add_generation_prompt=True,
77
  return_tensors="pt",
78
+ return_dict=True,
79
  ).to(model.device)
80
 
81
  with torch.inference_mode():
82
  output = model.generate(
83
+ **inputs,
84
  max_new_tokens=256,
85
+ do_sample=False,
 
 
86
  )
87
 
88
+ prompt_length = inputs["input_ids"].shape[-1]
89
+ print(tokenizer.decode(output[0][prompt_length:], skip_special_tokens=True))
90
  ```
91
 
92
  Use a recent Transformers release with Qwen3.5 support.
93
 
94
+ When multiple GPUs are visible, avoid `device_map="auto"` with this checkpoint.
95
+ Current Accelerate/Transformers releases may split the Qwen3.5 hybrid layers
96
+ across GPUs and produce invalid text. Pin the complete model to one GPU as shown
97
+ above. If sampling is desired, a tested starting point is `temperature=0.7`,
98
+ `top_p=0.8`, and `top_k=20`.
99
+
100
  ## Limitations
101
 
102
  The model may produce inaccurate, biased, or fabricated information. It has not
103
  been comprehensively evaluated for safety or high-stakes domains. Outputs should
104
  be independently verified before use in medical, legal, financial, or other
105
  consequential settings.