Text Generation
Transformers
Safetensors
English
Italian
quark
causal-lm
small-language-model
gqa
rope
swiglu
bash
code
custom_code
Instructions to use ThingAI/ARK-72M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ThingAI/ARK-72M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ThingAI/ARK-72M", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("ThingAI/ARK-72M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ThingAI/ARK-72M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ThingAI/ARK-72M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ThingAI/ARK-72M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ThingAI/ARK-72M
- SGLang
How to use ThingAI/ARK-72M 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/ARK-72M" \ --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": "ThingAI/ARK-72M", "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 "ThingAI/ARK-72M" \ --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": "ThingAI/ARK-72M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ThingAI/ARK-72M with Docker Model Runner:
docker model run hf.co/ThingAI/ARK-72M
fix: NaN guard in generate_text + _keys_to_ignore_on_load_missing
Browse files- modeling_quark.py +21 -9
modeling_quark.py
CHANGED
|
@@ -129,6 +129,8 @@ class QuarkPreTrainedModel(PreTrainedModel):
|
|
| 129 |
|
| 130 |
|
| 131 |
class QuarkForCausalLM(QuarkPreTrainedModel):
|
|
|
|
|
|
|
| 132 |
"""
|
| 133 |
Quark autoregressive language model.
|
| 134 |
Compatibile con AutoModelForCausalLM.from_pretrained(..., trust_remote_code=True)
|
|
@@ -192,17 +194,27 @@ class QuarkForCausalLM(QuarkPreTrainedModel):
|
|
| 192 |
for _ in range(max_new_tokens):
|
| 193 |
out = self(ctx[:, -self.config.max_seq_len:])
|
| 194 |
logits = out.logits[0, -1, :].float()
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
sorted_p, sorted_i = torch.sort(probs, descending=True)
|
| 199 |
-
cum_p
|
| 200 |
-
remove = cum_p - sorted_p > top_p
|
|
|
|
| 201 |
sorted_p[remove] = 0.0
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
| 206 |
ctx = torch.cat([ctx, token], dim=1)
|
| 207 |
if eos_token_id is not None and token.item() == eos_token_id:
|
| 208 |
break
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
class QuarkForCausalLM(QuarkPreTrainedModel):
|
| 132 |
+
# lm_head è tied con embed_tokens — non è missing, è intenzionale
|
| 133 |
+
_keys_to_ignore_on_load_missing = ["lm_head.weight"]
|
| 134 |
"""
|
| 135 |
Quark autoregressive language model.
|
| 136 |
Compatibile con AutoModelForCausalLM.from_pretrained(..., trust_remote_code=True)
|
|
|
|
| 194 |
for _ in range(max_new_tokens):
|
| 195 |
out = self(ctx[:, -self.config.max_seq_len:])
|
| 196 |
logits = out.logits[0, -1, :].float()
|
| 197 |
+
# Greedy se temperature=0 o logits degeneri
|
| 198 |
+
if temperature <= 0 or torch.isnan(logits).any() or torch.isinf(logits).any():
|
| 199 |
+
token = logits.argmax().view(1, 1)
|
| 200 |
+
else:
|
| 201 |
+
logits = logits / temperature
|
| 202 |
+
# Stabilizza prima del softmax
|
| 203 |
+
logits = logits - logits.max()
|
| 204 |
+
probs = F.softmax(logits, dim=-1)
|
| 205 |
+
probs = torch.clamp(probs, min=0.0)
|
| 206 |
+
# Top-p nucleus
|
| 207 |
sorted_p, sorted_i = torch.sort(probs, descending=True)
|
| 208 |
+
cum_p = torch.cumsum(sorted_p, dim=-1)
|
| 209 |
+
remove = (cum_p - sorted_p) > top_p
|
| 210 |
+
sorted_p = sorted_p.clone()
|
| 211 |
sorted_p[remove] = 0.0
|
| 212 |
+
total = sorted_p.sum()
|
| 213 |
+
if total <= 0:
|
| 214 |
+
token = sorted_i[0].view(1, 1)
|
| 215 |
+
else:
|
| 216 |
+
sorted_p /= total
|
| 217 |
+
token = sorted_i[torch.multinomial(sorted_p, 1)].unsqueeze(0).unsqueeze(0)
|
| 218 |
ctx = torch.cat([ctx, token], dim=1)
|
| 219 |
if eos_token_id is not None and token.item() == eos_token_id:
|
| 220 |
break
|