Instructions to use richarddzh/tiny-qwen3-30m-zh with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use richarddzh/tiny-qwen3-30m-zh with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="richarddzh/tiny-qwen3-30m-zh")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("richarddzh/tiny-qwen3-30m-zh") model = AutoModelForCausalLM.from_pretrained("richarddzh/tiny-qwen3-30m-zh", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use richarddzh/tiny-qwen3-30m-zh with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "richarddzh/tiny-qwen3-30m-zh" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "richarddzh/tiny-qwen3-30m-zh", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/richarddzh/tiny-qwen3-30m-zh
- SGLang
How to use richarddzh/tiny-qwen3-30m-zh 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 "richarddzh/tiny-qwen3-30m-zh" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "richarddzh/tiny-qwen3-30m-zh", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "richarddzh/tiny-qwen3-30m-zh" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "richarddzh/tiny-qwen3-30m-zh", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use richarddzh/tiny-qwen3-30m-zh with Docker Model Runner:
docker model run hf.co/richarddzh/tiny-qwen3-30m-zh
Tiny Qwen3 30M Chinese
Tiny Qwen3 30M Chinese is a 29.57M-parameter Chinese causal language model trained from scratch on the Chinese Small LM Corpus. It is a compact educational model for experimenting with tokenizer training, language-model pretraining, checkpointing, and Chinese text generation in the Hugging Face ecosystem.
This is a base language model, not an instruction-tuned or chat model.
Dataset
The model uses the train split of richarddzh/chinese-small-lm-corpus. The dataset is shuffled with seed 42, after which 10,000 documents are reserved for validation and the remaining documents are used for training.
Data preparation:
- Empty texts are discarded.
- Texts are tokenized without automatically added special tokens and separated with
<|endoftext|>. - Tokens from consecutive documents are concatenated and packed into fixed 512-token sequences without padding.
- Validation uses the same packing procedure and is limited to 256 packed sequences (131,072 tokens) per evaluation.
Tokenizer
A byte-level BPE tokenizer is trained from scratch on up to 100,000 training documents, with each document truncated to 2,000 characters for tokenizer training. It uses NFC normalization, an 8,192-token vocabulary, a minimum token frequency of 2, and the special tokens <|endoftext|>, <unk>, <|im_start|>, and <|im_end|>. The tokenizer supports sequences up to 1,024 tokens, while pretraining uses 512-token sequences.
Model architecture
| Parameter | Value |
|---|---|
| Architecture | Qwen3ForCausalLM |
| Parameters | 29,567,616 |
| Vocabulary size | 8,192 |
| Hidden size | 512 |
| Transformer layers | 9 |
| Attention heads | 8 |
| Key/value heads | 2 (GQA) |
| Head dimension | 64 |
| MLP intermediate size | 1,408 |
| Maximum position embeddings | 1,024 |
| RoPE theta | 1,000,000 |
| Tied input/output embeddings | Yes |
Training method
The model is pretrained from random initialization with the standard next-token causal language-modeling objective. The notebook uses the Hugging Face Trainer, packed iterable datasets, mixed precision when supported, gradient accumulation, periodic validation, and checkpoint-based resume.
Training configuration
| Parameter | Value |
|---|---|
| Optimizer | AdamW (adamw_torch_fused on CUDA) |
| Maximum optimizer steps | 30,000 |
| Sequence length | 512 |
| Micro-batch size | 32 sequences/device |
| Gradient accumulation | 2 steps |
| Effective batch size | 64 sequences / 32,768 tokens |
| Learning rate | 5e-4 |
| Scheduler | Cosine |
| Warmup steps | 200 |
| Weight decay | 0.1 |
| Adam betas | (0.9, 0.95) |
| Gradient clipping | 1.0 |
| Precision | BF16 when supported; otherwise FP16 on CUDA or FP32 on CPU |
| Evaluation interval | 250 steps |
| Checkpoint interval | 250 steps |
| Random seed | 42 |
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo_id = "richarddzh/tiny-qwen3-30m-zh"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForCausalLM.from_pretrained(repo_id)
prompt = "问题:太阳是地球的什么?回答:太阳是"
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
with torch.no_grad():
output = model.generate(
**inputs,
max_new_tokens=80,
do_sample=True,
temperature=0.8,
top_p=0.9,
repetition_penalty=1.1,
pad_token_id=tokenizer.eos_token_id,
)
print(tokenizer.decode(output[0], skip_special_tokens=True))
Reproducibility
The complete data preparation, tokenizer training, model configuration, pretraining, evaluation, and upload workflow is available in the training notebook.
Limitations
This is a small experimental base model. Its factual knowledge, reasoning ability, instruction-following behavior, and context handling are limited. Generated text may be repetitive, inconsistent, factually incorrect, or reflect biases and artifacts in the training corpus. Do not use it for high-stakes decisions or assume its outputs are accurate.
- Downloads last month
- 480