Text Generation
Transformers
Safetensors
Uzbek
English
qwen3_5_text
qwen3.5
uzbek
conversational
translation
text-generation-inference
Instructions to use NeuronUz/NeuronAI-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NeuronUz/NeuronAI-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NeuronUz/NeuronAI-2B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("NeuronUz/NeuronAI-2B") model = AutoModelForCausalLM.from_pretrained("NeuronUz/NeuronAI-2B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use NeuronUz/NeuronAI-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NeuronUz/NeuronAI-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NeuronUz/NeuronAI-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/NeuronUz/NeuronAI-2B
- SGLang
How to use NeuronUz/NeuronAI-2B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "NeuronUz/NeuronAI-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NeuronUz/NeuronAI-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "NeuronUz/NeuronAI-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NeuronUz/NeuronAI-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use NeuronUz/NeuronAI-2B with Docker Model Runner:
docker model run hf.co/NeuronUz/NeuronAI-2B
Document verified concise four-sentence inference config
Browse files
README.md
CHANGED
|
@@ -52,11 +52,35 @@ included in this repository.
|
|
| 52 |
## Usage
|
| 53 |
|
| 54 |
```python
|
|
|
|
| 55 |
import torch
|
| 56 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|
|
@@ -67,7 +91,14 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 67 |
)
|
| 68 |
|
| 69 |
messages = [
|
| 70 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
{"role": "user", "content": "O'zbekiston haqida qisqacha ma'lumot bering."},
|
| 72 |
]
|
| 73 |
|
|
@@ -78,15 +109,43 @@ inputs = tokenizer.apply_chat_template(
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
```
|
| 91 |
|
| 92 |
Use a recent Transformers release with Qwen3.5 support.
|
|
@@ -94,8 +153,10 @@ Use a recent Transformers release with Qwen3.5 support.
|
|
| 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.
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
|
| 100 |
## Limitations
|
| 101 |
|
|
|
|
| 52 |
## Usage
|
| 53 |
|
| 54 |
```python
|
| 55 |
+
import re
|
| 56 |
import torch
|
| 57 |
+
from transformers import (
|
| 58 |
+
AutoModelForCausalLM,
|
| 59 |
+
AutoTokenizer,
|
| 60 |
+
StoppingCriteria,
|
| 61 |
+
StoppingCriteriaList,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class SentenceLimitCriteria(StoppingCriteria):
|
| 66 |
+
"""Stop after a fixed number of complete generated sentences."""
|
| 67 |
+
|
| 68 |
+
def __init__(self, tokenizer, prompt_length, max_sentences=4):
|
| 69 |
+
self.tokenizer = tokenizer
|
| 70 |
+
self.prompt_length = prompt_length
|
| 71 |
+
self.max_sentences = max_sentences
|
| 72 |
+
|
| 73 |
+
def __call__(self, input_ids, scores, **kwargs):
|
| 74 |
+
generated = self.tokenizer.decode(
|
| 75 |
+
input_ids[0, self.prompt_length:], skip_special_tokens=True
|
| 76 |
+
)
|
| 77 |
+
endings = re.findall(r'[.!?](?:["\'’”)]*)?\s+', generated)
|
| 78 |
+
return len(endings) >= self.max_sentences
|
| 79 |
+
|
| 80 |
|
| 81 |
model_id = "NeuronUz/qwen3.5-2b-fine-tuned"
|
| 82 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 83 |
+
max_sentences = 4
|
| 84 |
|
| 85 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 86 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 91 |
)
|
| 92 |
|
| 93 |
messages = [
|
| 94 |
+
{
|
| 95 |
+
"role": "system",
|
| 96 |
+
"content": (
|
| 97 |
+
"Siz foydali AI yordamchisiz. Javoblarni qisqa va aniq yozing. "
|
| 98 |
+
"Agar foydalanuvchi batafsil javob so'ramasa, odatda 2-4 ta "
|
| 99 |
+
"to'liq gap bilan javob bering."
|
| 100 |
+
),
|
| 101 |
+
},
|
| 102 |
{"role": "user", "content": "O'zbekiston haqida qisqacha ma'lumot bering."},
|
| 103 |
]
|
| 104 |
|
|
|
|
| 109 |
return_dict=True,
|
| 110 |
).to(model.device)
|
| 111 |
|
| 112 |
+
im_end_id = tokenizer.convert_tokens_to_ids("<|im_end|>")
|
| 113 |
+
eos_ids = [tokenizer.eos_token_id, im_end_id]
|
| 114 |
+
stopping_criteria = StoppingCriteriaList(
|
| 115 |
+
[
|
| 116 |
+
SentenceLimitCriteria(
|
| 117 |
+
tokenizer,
|
| 118 |
+
prompt_length=inputs["input_ids"].shape[-1],
|
| 119 |
+
max_sentences=max_sentences,
|
| 120 |
+
)
|
| 121 |
+
]
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
with torch.inference_mode():
|
| 125 |
output = model.generate(
|
| 126 |
**inputs,
|
| 127 |
max_new_tokens=256,
|
| 128 |
do_sample=False,
|
| 129 |
+
repetition_penalty=1.15,
|
| 130 |
+
no_repeat_ngram_size=3,
|
| 131 |
+
eos_token_id=eos_ids,
|
| 132 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 133 |
+
stopping_criteria=stopping_criteria,
|
| 134 |
)
|
| 135 |
|
| 136 |
prompt_length = inputs["input_ids"].shape[-1]
|
| 137 |
+
reply = tokenizer.decode(
|
| 138 |
+
output[0][prompt_length:], skip_special_tokens=True
|
| 139 |
+
).strip()
|
| 140 |
+
|
| 141 |
+
# A token can contain the final period and the start of the next word, so trim
|
| 142 |
+
# the displayed output back to the fourth complete sentence.
|
| 143 |
+
sentence_end_re = re.compile(r'[.!?](?:["\'’”)]*)?(?=\s|$)')
|
| 144 |
+
sentence_endings = list(sentence_end_re.finditer(reply))
|
| 145 |
+
if len(sentence_endings) >= max_sentences:
|
| 146 |
+
reply = reply[:sentence_endings[max_sentences - 1].end()].strip()
|
| 147 |
+
|
| 148 |
+
print(reply)
|
| 149 |
```
|
| 150 |
|
| 151 |
Use a recent Transformers release with Qwen3.5 support.
|
|
|
|
| 153 |
When multiple GPUs are visible, avoid `device_map="auto"` with this checkpoint.
|
| 154 |
Current Accelerate/Transformers releases may split the Qwen3.5 hybrid layers
|
| 155 |
across GPUs and produce invalid text. Pin the complete model to one GPU as shown
|
| 156 |
+
above. The example uses greedy decoding (`do_sample=False`, equivalent to
|
| 157 |
+
temperature 0 in the local chat script) and limits normal answers to four
|
| 158 |
+
complete sentences. If sampling is desired, a tested starting point is
|
| 159 |
+
`temperature=0.7`, `top_p=0.8`, and `top_k=20`.
|
| 160 |
|
| 161 |
## Limitations
|
| 162 |
|