pip install -U transformers accelerate torch
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="Qwen/Qwen3-8B",
device_map="auto"
)
messages = [
{"role": "user", "content": "Составь 5 задач по вероятности для 10 класса"}
]
result = pipe(messages, max_new_tokens=600)
Если модель не помещается, используйте 8- или 4-битное квантование через bitsandbytes.
pip install -U transformers accelerate bitsandbytes
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
q = BitsAndBytesConfig(load_in_4bit=True)
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen3-8B",
quantization_config=q,
device_map="auto"
)