Text Generation
Transformers
Safetensors
Italian
English
quark
causal-lm
bilingual
italian
english
small-language-model
trained-from-scratch
conversational
custom_code
Instructions to use ThingAI/ARK-270M-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ThingAI/ARK-270M-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ThingAI/ARK-270M-Base", 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/ARK-270M-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ThingAI/ARK-270M-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ThingAI/ARK-270M-Base" # 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/ARK-270M-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ThingAI/ARK-270M-Base
- SGLang
How to use ThingAI/ARK-270M-Base 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-270M-Base" \ --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/ARK-270M-Base", "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/ARK-270M-Base" \ --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/ARK-270M-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ThingAI/ARK-270M-Base with Docker Model Runner:
docker model run hf.co/ThingAI/ARK-270M-Base
Upload modeling_quark.py with huggingface_hub
Browse files- modeling_quark.py +12 -2
modeling_quark.py
CHANGED
|
@@ -74,13 +74,22 @@ class QuarkForCausalLM(QuarkPreTrainedModel):
|
|
| 74 |
self.layers=nn.ModuleList([QuarkBlock(config) for _ in range(config.n_layers)])
|
| 75 |
self.norm=QuarkRMSNorm(config.d_model,config.rms_eps)
|
| 76 |
self.lm_head=nn.Linear(config.d_model,config.vocab_size,bias=False)
|
| 77 |
-
self.lm_head.weight=self.embed_tokens.weight
|
| 78 |
self.post_init()
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
def get_input_embeddings(self): return self.embed_tokens
|
| 81 |
def set_input_embeddings(self, v): self.embed_tokens=v
|
| 82 |
def get_output_embeddings(self): return self.lm_head
|
| 83 |
def set_output_embeddings(self, v): self.lm_head=v
|
|
|
|
| 84 |
def forward(self, input_ids, attention_mask=None, labels=None, **kwargs):
|
| 85 |
h=self.embed_tokens(input_ids)
|
| 86 |
for layer in self.layers: h=layer(h)
|
|
@@ -90,4 +99,5 @@ class QuarkForCausalLM(QuarkPreTrainedModel):
|
|
| 90 |
loss=F.cross_entropy(logits[...,:-1,:].contiguous().view(-1,self.config.vocab_size),
|
| 91 |
labels[...,1:].contiguous().view(-1),ignore_index=-100)
|
| 92 |
return CausalLMOutputWithPast(loss=loss, logits=logits)
|
|
|
|
| 93 |
def prepare_inputs_for_generation(self, input_ids, **kwargs): return {"input_ids": input_ids}
|
|
|
|
| 74 |
self.layers=nn.ModuleList([QuarkBlock(config) for _ in range(config.n_layers)])
|
| 75 |
self.norm=QuarkRMSNorm(config.d_model,config.rms_eps)
|
| 76 |
self.lm_head=nn.Linear(config.d_model,config.vocab_size,bias=False)
|
| 77 |
+
self.lm_head.weight=self.embed_tokens.weight # weight tying
|
| 78 |
self.post_init()
|
| 79 |
+
|
| 80 |
+
def _load_from_state_dict(self, state_dict, prefix, *args, **kwargs):
|
| 81 |
+
"""Se lm_head.weight manca, copia da embed_tokens.weight (weight tying)"""
|
| 82 |
+
lm_key = f"{prefix}lm_head.weight"
|
| 83 |
+
emb_key = f"{prefix}embed_tokens.weight"
|
| 84 |
+
if lm_key not in state_dict and emb_key in state_dict:
|
| 85 |
+
state_dict[lm_key] = state_dict[emb_key].clone()
|
| 86 |
+
super()._load_from_state_dict(state_dict, prefix, *args, **kwargs)
|
| 87 |
+
|
| 88 |
def get_input_embeddings(self): return self.embed_tokens
|
| 89 |
def set_input_embeddings(self, v): self.embed_tokens=v
|
| 90 |
def get_output_embeddings(self): return self.lm_head
|
| 91 |
def set_output_embeddings(self, v): self.lm_head=v
|
| 92 |
+
|
| 93 |
def forward(self, input_ids, attention_mask=None, labels=None, **kwargs):
|
| 94 |
h=self.embed_tokens(input_ids)
|
| 95 |
for layer in self.layers: h=layer(h)
|
|
|
|
| 99 |
loss=F.cross_entropy(logits[...,:-1,:].contiguous().view(-1,self.config.vocab_size),
|
| 100 |
labels[...,1:].contiguous().view(-1),ignore_index=-100)
|
| 101 |
return CausalLMOutputWithPast(loss=loss, logits=logits)
|
| 102 |
+
|
| 103 |
def prepare_inputs_for_generation(self, input_ids, **kwargs): return {"input_ids": input_ids}
|