Text Generation
Transformers
Safetensors
English
deepseek_nano
math
experiment
Mixture of Experts
deepseek
from-scratch
tiny-model
cpu
deepseek-v3-architecture
custom_code
Instructions to use AxionLab-Co/AxionMoE-350k-A250k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AxionLab-Co/AxionMoE-350k-A250k with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AxionLab-Co/AxionMoE-350k-A250k", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("AxionLab-Co/AxionMoE-350k-A250k", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AxionLab-Co/AxionMoE-350k-A250k with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AxionLab-Co/AxionMoE-350k-A250k" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AxionLab-Co/AxionMoE-350k-A250k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AxionLab-Co/AxionMoE-350k-A250k
- SGLang
How to use AxionLab-Co/AxionMoE-350k-A250k 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 "AxionLab-Co/AxionMoE-350k-A250k" \ --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": "AxionLab-Co/AxionMoE-350k-A250k", "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 "AxionLab-Co/AxionMoE-350k-A250k" \ --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": "AxionLab-Co/AxionMoE-350k-A250k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AxionLab-Co/AxionMoE-350k-A250k with Docker Model Runner:
docker model run hf.co/AxionLab-Co/AxionMoE-350k-A250k
Update modeling_axion.py
Browse files- modeling_axion.py +15 -1
modeling_axion.py
CHANGED
|
@@ -69,6 +69,19 @@ class DeepSeekNanoForCausalLM(PreTrainedModel):
|
|
| 69 |
labels=None, use_cache=False, **kwargs):
|
| 70 |
x = self.embed(input_ids)
|
| 71 |
new_caches = [] if use_cache else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
for i, block in enumerate(self.blocks):
|
| 73 |
cache = past_key_values[i] if past_key_values else None
|
| 74 |
x, nc = block(x, kv_cache=cache, use_cache=use_cache)
|
|
@@ -82,6 +95,7 @@ class DeepSeekNanoForCausalLM(PreTrainedModel):
|
|
| 82 |
return CausalLMOutputWithPast(loss=loss, logits=logits, past_key_values=new_caches)
|
| 83 |
|
| 84 |
def prepare_inputs_for_generation(self, input_ids, past_key_values=None, **kwargs):
|
| 85 |
-
|
|
|
|
| 86 |
input_ids = input_ids[:, -1:]
|
| 87 |
return {"input_ids": input_ids, "past_key_values": past_key_values, "use_cache": True}
|
|
|
|
| 69 |
labels=None, use_cache=False, **kwargs):
|
| 70 |
x = self.embed(input_ids)
|
| 71 |
new_caches = [] if use_cache else None
|
| 72 |
+
|
| 73 |
+
# Compatibilidade com DynamicCache (Transformers >= 4.36)
|
| 74 |
+
# Converte para lista simples que o nosso MLA entende
|
| 75 |
+
if past_key_values is not None and not isinstance(past_key_values, list):
|
| 76 |
+
try:
|
| 77 |
+
past_key_values = [
|
| 78 |
+
(past_key_values.key_cache[i], past_key_values.value_cache[i])
|
| 79 |
+
if i < len(past_key_values.key_cache) else None
|
| 80 |
+
for i in range(len(self.blocks))
|
| 81 |
+
]
|
| 82 |
+
except Exception:
|
| 83 |
+
past_key_values = None
|
| 84 |
+
|
| 85 |
for i, block in enumerate(self.blocks):
|
| 86 |
cache = past_key_values[i] if past_key_values else None
|
| 87 |
x, nc = block(x, kv_cache=cache, use_cache=use_cache)
|
|
|
|
| 95 |
return CausalLMOutputWithPast(loss=loss, logits=logits, past_key_values=new_caches)
|
| 96 |
|
| 97 |
def prepare_inputs_for_generation(self, input_ids, past_key_values=None, **kwargs):
|
| 98 |
+
# Se tem cache (qualquer tipo), usa s贸 o 煤ltimo token
|
| 99 |
+
if past_key_values is not None:
|
| 100 |
input_ids = input_ids[:, -1:]
|
| 101 |
return {"input_ids": input_ids, "past_key_values": past_key_values, "use_cache": True}
|