Text Generation
Transformers
Safetensors
Italian
English
quark
causal-lm
bilingual
italian
english
small-language-model
trained-from-scratch
instruct
sft
chat
conversational
custom_code
Instructions to use ThingAI/Quark-270m-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ThingAI/Quark-270m-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ThingAI/Quark-270m-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("ThingAI/Quark-270m-Instruct", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ThingAI/Quark-270m-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ThingAI/Quark-270m-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ThingAI/Quark-270m-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ThingAI/Quark-270m-Instruct
- SGLang
How to use ThingAI/Quark-270m-Instruct 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 "ThingAI/Quark-270m-Instruct" \ --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": "ThingAI/Quark-270m-Instruct", "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 "ThingAI/Quark-270m-Instruct" \ --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": "ThingAI/Quark-270m-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ThingAI/Quark-270m-Instruct with Docker Model Runner:
docker model run hf.co/ThingAI/Quark-270m-Instruct
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- it
|
| 4 |
+
- en
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
tags:
|
| 7 |
+
- text-generation
|
| 8 |
+
- causal-lm
|
| 9 |
+
- bilingual
|
| 10 |
+
- italian
|
| 11 |
+
- english
|
| 12 |
+
- small-language-model
|
| 13 |
+
- trained-from-scratch
|
| 14 |
+
- quark
|
| 15 |
+
- instruct
|
| 16 |
+
- sft
|
| 17 |
+
- chat
|
| 18 |
+
library_name: transformers
|
| 19 |
+
pipeline_tag: text-generation
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# Quark-270M-Instruct โ Bilingual Chat Model
|
| 23 |
+
Quark-270M-Instruct is the **instruction-tuned** version of [Quark-270M Base](https://huggingface.co/ThingAI/Quark-270m-Base), fine-tuned for conversational use in Italian and English. Built entirely from scratch by [ThingsAI](https://things-ai.org).
|
| 24 |
+
|
| 25 |
+
### Highlights
|
| 26 |
+
|
| 27 |
+
- ๐ฎ๐น๐ฌ๐ง **Bilingual:** Responds naturally in Italian and English
|
| 28 |
+
- ๐ฌ **Conversational:** Greetings, Q&A, general knowledge
|
| 29 |
+
- ๐ป **Code-aware:** Python basics and terminal commands
|
| 30 |
+
- ๐ชถ **Lightweight:** Runs on consumer GPUs (< 1GB VRAM in BF16)
|
| 31 |
+
|
| 32 |
+
## Quick Start
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 36 |
+
import torch
|
| 37 |
+
|
| 38 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 39 |
+
"ThingAI/Quark-270m-Instruct",
|
| 40 |
+
trust_remote_code=True,
|
| 41 |
+
torch_dtype=torch.bfloat16
|
| 42 |
+
).cuda()
|
| 43 |
+
model.lm_head.weight = model.embed_tokens.weight # ensure weight tying
|
| 44 |
+
|
| 45 |
+
tokenizer = AutoTokenizer.from_pretrained("ThingAI/Quark-270m-Instruct")
|
| 46 |
+
|
| 47 |
+
prompt = "<|user|>\nCiao, come stai?\n<|end|>\n<|assistant|>\n"
|
| 48 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 49 |
+
out = model.generate(**inputs, max_new_tokens=150, do_sample=True, temperature=0.7, top_k=40)
|
| 50 |
+
print(tokenizer.decode(out[0], skip_special_tokens=False))
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Chat Format
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
<|user|>
|
| 57 |
+
{user message}
|
| 58 |
+
<|end|>
|
| 59 |
+
<|assistant|>
|
| 60 |
+
{model response}
|
| 61 |
+
<|end|>
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
Multi-turn:
|
| 65 |
+
|
| 66 |
+
```
|
| 67 |
+
<|user|>
|
| 68 |
+
Ciao!
|
| 69 |
+
<|end|>
|
| 70 |
+
<|assistant|>
|
| 71 |
+
Ciao! Come posso aiutarti?
|
| 72 |
+
<|end|>
|
| 73 |
+
<|user|>
|
| 74 |
+
Cos'รจ l'intelligenza artificiale?
|
| 75 |
+
<|end|>
|
| 76 |
+
<|assistant|>
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Model Details
|
| 80 |
+
|
| 81 |
+
| | |
|
| 82 |
+
|---|---|
|
| 83 |
+
| **Base Model** | [Quark-270M Base](https://huggingface.co/ThingAI/Quark-270m-Base) |
|
| 84 |
+
| **Parameters** | 252M (with weight tying) |
|
| 85 |
+
| **Architecture** | Decoder-only Transformer (GQA, SwiGLU, RMSNorm, RoPE) |
|
| 86 |
+
| **Vocabulary** | 65,537 tokens |
|
| 87 |
+
| **Context Length** | 2,048 tokens |
|
| 88 |
+
| **Precision** | BF16 |
|
| 89 |
+
| **Languages** | Italian, English |
|
| 90 |
+
|
| 91 |
+
### Architecture
|
| 92 |
+
|
| 93 |
+
| | |
|
| 94 |
+
|---|---|
|
| 95 |
+
| d_model | 768 |
|
| 96 |
+
| Layers | 32 |
|
| 97 |
+
| Query Heads | 12 |
|
| 98 |
+
| KV Heads | 4 |
|
| 99 |
+
| Head Dim | 64 |
|
| 100 |
+
| FFN Dim | 2,048 |
|
| 101 |
+
| Activation | SwiGLU |
|
| 102 |
+
|
| 103 |
+
## Training
|
| 104 |
+
|
| 105 |
+
### Base Pretraining
|
| 106 |
+
|
| 107 |
+
~10B tokens on a bilingual mix (Italian 50%, English 43%, Code 7%) on NVIDIA B200. See [Quark-270M Base](https://huggingface.co/ThingAI/Quark-270m-Base) for details.
|
| 108 |
+
|
| 109 |
+
### SFT (Instruction Tuning)
|
| 110 |
+
|
| 111 |
+
Fine-tuned on a diverse mix of conversational and instructional data:
|
| 112 |
+
|
| 113 |
+
| Dataset | Examples | Type |
|
| 114 |
+
|---|---|---|
|
| 115 |
+
| FreedomIntelligence/alpaca-gpt4-italian | ~52,000 | Italian instructions |
|
| 116 |
+
| HuggingFaceH4/no_robots | ~9,500 | English conversations |
|
| 117 |
+
| m-a-p/CodeFeedback-Filtered-Instruction | 5,000 | Code instructions |
|
| 118 |
+
| yogeshm/text_to_bash (ร80) | ~9,900 | Terminal commands |
|
| 119 |
+
| Custom chitchat (ร100) | ~3,000 | Identity, greetings, basic Q&A |
|
| 120 |
+
| **Total** | **~80,000** | |
|
| 121 |
+
|
| 122 |
+
| | |
|
| 123 |
+
|---|---|
|
| 124 |
+
| **Hardware** | NVIDIA B200 |
|
| 125 |
+
| **Epochs** | 3 |
|
| 126 |
+
| **Learning Rate** | 2e-5 (cosine decay) |
|
| 127 |
+
| **Batch Size** | 16 ร 4 = 64 effective |
|
| 128 |
+
| **Sequence Length** | 512 |
|
| 129 |
+
|
| 130 |
+
## Inference Server
|
| 131 |
+
|
| 132 |
+
Quark-270M-Instruct powers [Things Chat](https://chat.things-ai.org) via a self-hosted FastAPI server with SSE streaming, conversation memory, web search, and content moderation.
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
QUARK_MODEL_DIR=./Quark-270m-Instruct python app.py
|
| 136 |
+
# โ http://localhost:5005
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
### API
|
| 140 |
+
|
| 141 |
+
```bash
|
| 142 |
+
# Streaming
|
| 143 |
+
curl -X POST http://localhost:5005/api/chat/stream \
|
| 144 |
+
-H "Content-Type: application/json" \
|
| 145 |
+
-d '{"text": "Ciao!", "session_id": "user1"}'
|
| 146 |
+
|
| 147 |
+
# Batch
|
| 148 |
+
curl -X POST http://localhost:5005/api/chat \
|
| 149 |
+
-H "Content-Type: application/json" \
|
| 150 |
+
-d '{"text": "What is AI?"}'
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Limitations
|
| 154 |
+
|
| 155 |
+
- **252M is small:** Limited factual knowledge, prone to hallucination
|
| 156 |
+
- **Mathematics:** Unreliable beyond basic arithmetic
|
| 157 |
+
- **Code:** Generates plausible but often non-functional code
|
| 158 |
+
- **Context:** 2,048 token window
|
| 159 |
+
- **No system prompt:** The model was not trained with `<|system|>` tags
|
| 160 |
+
|
| 161 |
+
### Good for
|
| 162 |
+
|
| 163 |
+
- Self-hosted bilingual chatbot
|
| 164 |
+
- Learning about LLM training from scratch
|
| 165 |
+
- Terminal command assistance
|
| 166 |
+
- Light conversational AI
|
| 167 |
+
|
| 168 |
+
### Not suited for
|
| 169 |
+
|
| 170 |
+
- Factual Q&A requiring accuracy
|
| 171 |
+
- Complex reasoning or math
|
| 172 |
+
- Production-grade code generation
|
| 173 |
+
- Safety-critical applications
|
| 174 |
+
|
| 175 |
+
## The Quark Family
|
| 176 |
+
|
| 177 |
+
| Model | Parameters | Type |
|
| 178 |
+
|---|---|---|
|
| 179 |
+
| [Quark-50M](https://huggingface.co/ThingAI/Quark-50m) | 51M | Base |
|
| 180 |
+
| [Quark-135M](https://huggingface.co/ThingAI/Quark-135m) | 135M | Base |
|
| 181 |
+
| [Quark-270M Base](https://huggingface.co/ThingAI/Quark-270m-Base) | 252M | Base |
|
| 182 |
+
| **Quark-270M-Instruct** | **252M** | **Chat** |
|
| 183 |
+
|
| 184 |
+
## Links
|
| 185 |
+
|
| 186 |
+
- ๐ [ThingsAI](https://things-ai.org)
|
| 187 |
+
- ๐ฌ [Things Chat](https://chat.things-ai.org)
|
| 188 |
+
- ๐ค [QuarkTokenizer](https://huggingface.co/ThingAI/QuarkTokenizer)
|
| 189 |
+
- ๐ [Open SLM Leaderboard](https://huggingface.co/spaces/AxiomicLabs/Open_SLM_Leaderboard)
|
| 190 |
+
|
| 191 |
+
---
|
| 192 |
+
|
| 193 |
+
*Built from scratch by ThingsAI ๐ฎ๐น*
|