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: weight tying via embed_tokens.weight.T, rimuove lm_head
Browse files- modeling_quark.py +8 -8
modeling_quark.py
CHANGED
|
@@ -138,24 +138,21 @@ class QuarkForCausalLM(QuarkPreTrainedModel):
|
|
| 138 |
self.embed_tokens = nn.Embedding(config.vocab_size, config.d_model)
|
| 139 |
self.layers = nn.ModuleList([TransformerBlock(config) for _ in range(config.n_layers)])
|
| 140 |
self.norm = RMSNorm(config.d_model, config.rms_eps)
|
| 141 |
-
|
| 142 |
-
self.lm_head.weight = self.embed_tokens.weight
|
| 143 |
self.post_init()
|
| 144 |
|
| 145 |
def get_input_embeddings(self): return self.embed_tokens
|
| 146 |
def set_input_embeddings(self, v): self.embed_tokens = v
|
| 147 |
-
def get_output_embeddings(self): return
|
| 148 |
-
def
|
| 149 |
-
|
| 150 |
-
def tie_weights(self, **kwargs):
|
| 151 |
-
self.lm_head.weight = self.embed_tokens.weight
|
| 152 |
|
| 153 |
def forward(self, input_ids=None, attention_mask=None, labels=None, **kwargs):
|
| 154 |
x = self.embed_tokens(input_ids)
|
| 155 |
for layer in self.layers:
|
| 156 |
x = layer(x)
|
| 157 |
x = self.norm(x)
|
| 158 |
-
|
|
|
|
| 159 |
loss = None
|
| 160 |
if labels is not None:
|
| 161 |
loss = F.cross_entropy(
|
|
@@ -172,6 +169,9 @@ class QuarkForCausalLM(QuarkPreTrainedModel):
|
|
| 172 |
for _ in range(max_new_tokens):
|
| 173 |
out = self(ctx[:, -self.config.max_seq_len:])
|
| 174 |
logits = out.logits[0, -1, :].float()
|
|
|
|
|
|
|
|
|
|
| 175 |
if temperature <= 0:
|
| 176 |
token = logits.argmax().view(1, 1)
|
| 177 |
else:
|
|
|
|
| 138 |
self.embed_tokens = nn.Embedding(config.vocab_size, config.d_model)
|
| 139 |
self.layers = nn.ModuleList([TransformerBlock(config) for _ in range(config.n_layers)])
|
| 140 |
self.norm = RMSNorm(config.d_model, config.rms_eps)
|
| 141 |
+
# lm_head usa embed_tokens.weight (weight tying) — non è un parametro separato
|
|
|
|
| 142 |
self.post_init()
|
| 143 |
|
| 144 |
def get_input_embeddings(self): return self.embed_tokens
|
| 145 |
def set_input_embeddings(self, v): self.embed_tokens = v
|
| 146 |
+
def get_output_embeddings(self): return None
|
| 147 |
+
def tie_weights(self, **kwargs): pass
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
def forward(self, input_ids=None, attention_mask=None, labels=None, **kwargs):
|
| 150 |
x = self.embed_tokens(input_ids)
|
| 151 |
for layer in self.layers:
|
| 152 |
x = layer(x)
|
| 153 |
x = self.norm(x)
|
| 154 |
+
# Weight tying: proiezione finale con la stessa matrice degli embedding
|
| 155 |
+
logits = x @ self.embed_tokens.weight.T
|
| 156 |
loss = None
|
| 157 |
if labels is not None:
|
| 158 |
loss = F.cross_entropy(
|
|
|
|
| 169 |
for _ in range(max_new_tokens):
|
| 170 |
out = self(ctx[:, -self.config.max_seq_len:])
|
| 171 |
logits = out.logits[0, -1, :].float()
|
| 172 |
+
if logits.isnan().any() or logits.isinf().any():
|
| 173 |
+
logits = torch.zeros_like(logits)
|
| 174 |
+
logits[2] = 1.0 # forza </s>
|
| 175 |
if temperature <= 0:
|
| 176 |
token = logits.argmax().view(1, 1)
|
| 177 |
else:
|