Text Generation
Transformers
Safetensors
Russian
English
deepseek_v3
gigachat3
testing
tiny
conversational
text-generation-inference
Instructions to use optimum-intel-internal-testing/tiny-random-gigachat3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use optimum-intel-internal-testing/tiny-random-gigachat3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="optimum-intel-internal-testing/tiny-random-gigachat3") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("optimum-intel-internal-testing/tiny-random-gigachat3") model = AutoModelForCausalLM.from_pretrained("optimum-intel-internal-testing/tiny-random-gigachat3", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use optimum-intel-internal-testing/tiny-random-gigachat3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "optimum-intel-internal-testing/tiny-random-gigachat3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "optimum-intel-internal-testing/tiny-random-gigachat3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/optimum-intel-internal-testing/tiny-random-gigachat3
- SGLang
How to use optimum-intel-internal-testing/tiny-random-gigachat3 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 "optimum-intel-internal-testing/tiny-random-gigachat3" \ --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": "optimum-intel-internal-testing/tiny-random-gigachat3", "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 "optimum-intel-internal-testing/tiny-random-gigachat3" \ --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": "optimum-intel-internal-testing/tiny-random-gigachat3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use optimum-intel-internal-testing/tiny-random-gigachat3 with Docker Model Runner:
docker model run hf.co/optimum-intel-internal-testing/tiny-random-gigachat3
Commit ·
1a800b4
1
Parent(s): c10a920
add README
Browse files
README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Tiny model creation script:
|
| 2 |
+
|
| 3 |
+
```pthon
|
| 4 |
+
"""
|
| 5 |
+
Create a tiny GigaChat3 model for testing .
|
| 6 |
+
|
| 7 |
+
GigaChat3 uses DeepseekV3Config (no text_config/vision_config sub-objects).
|
| 8 |
+
Key constraint: qk_head_dim == qk_nope_head_dim + qk_rope_head_dim
|
| 9 |
+
"""
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
| 15 |
+
|
| 16 |
+
model_id = "ai-sage/GigaChat3-10B-A1.8B-bf16"
|
| 17 |
+
output_dir = "./tiny-gigachat3"
|
| 18 |
+
|
| 19 |
+
config = AutoConfig.from_pretrained(model_id)
|
| 20 |
+
config.num_hidden_layers = 2
|
| 21 |
+
config.num_attention_heads = 2
|
| 22 |
+
config.num_key_value_heads = 2
|
| 23 |
+
config.hidden_size = 32
|
| 24 |
+
config.intermediate_size = 64
|
| 25 |
+
config.moe_intermediate_size = 32
|
| 26 |
+
config.n_routed_experts = 4
|
| 27 |
+
config.n_shared_experts = 1
|
| 28 |
+
config.num_experts_per_tok = 2
|
| 29 |
+
config.kv_lora_rank = 8
|
| 30 |
+
config.q_lora_rank = None
|
| 31 |
+
|
| 32 |
+
# Attention head dims — MUST satisfy: qk_head_dim == qk_nope_head_dim + qk_rope_head_dim
|
| 33 |
+
config.qk_nope_head_dim = 4
|
| 34 |
+
config.qk_rope_head_dim = 2
|
| 35 |
+
config.qk_head_dim = 6 # 4 + 2
|
| 36 |
+
config.v_head_dim = 4
|
| 37 |
+
config.head_dim = config.qk_rope_head_dim # used by RoPE
|
| 38 |
+
|
| 39 |
+
TINY_VOCAB = 32000
|
| 40 |
+
config.vocab_size = TINY_VOCAB
|
| 41 |
+
|
| 42 |
+
assert config.qk_head_dim == config.qk_nope_head_dim + config.qk_rope_head_dim
|
| 43 |
+
|
| 44 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 45 |
+
model = AutoModelForCausalLM.from_config(config)
|
| 46 |
+
model.save_pretrained(output_dir)
|
| 47 |
+
|
| 48 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 49 |
+
tokenizer.save_pretrained(output_dir)
|
| 50 |
+
|
| 51 |
+
tok_path = os.path.join(output_dir, "tokenizer.json")
|
| 52 |
+
with open(tok_path, encoding="utf-8") as f:
|
| 53 |
+
tok_data = json.load(f)
|
| 54 |
+
|
| 55 |
+
if "model" in tok_data and "vocab" in tok_data["model"]:
|
| 56 |
+
tok_data["model"]["vocab"] = {
|
| 57 |
+
k: v for k, v in tok_data["model"]["vocab"].items() if v < TINY_VOCAB
|
| 58 |
+
}
|
| 59 |
+
tok_data["model"]["merges"] = []
|
| 60 |
+
|
| 61 |
+
if "added_tokens" in tok_data:
|
| 62 |
+
tok_data["added_tokens"] = [t for t in tok_data["added_tokens"] if t["id"] < TINY_VOCAB]
|
| 63 |
+
|
| 64 |
+
with open(tok_path, "w", encoding="utf-8") as f:
|
| 65 |
+
json.dump(tok_data, f, ensure_ascii=False)
|
| 66 |
+
|
| 67 |
+
# ── Smoke test ───────────────────────────────────────────────────────────────
|
| 68 |
+
tokens = tokenizer("Hello world", return_tensors="pt")
|
| 69 |
+
tokens.pop("token_type_ids", None)
|
| 70 |
+
with torch.no_grad():
|
| 71 |
+
out = model(**tokens)
|
| 72 |
+
|
| 73 |
+
total_mb = sum(os.path.getsize(os.path.join(output_dir, fn)) for fn in os.listdir(output_dir)) / 1e6
|
| 74 |
+
print(f"shape={out.logits.shape} params={sum(p.numel() for p in model.parameters())/1e6:.2f}M size={total_mb:.1f} MB")
|
| 75 |
+
|
| 76 |
+
```
|