Text Generation
Transformers
Safetensors
tinyqwen3_novelty
qwen3
causal-lm
tiny-language-model
novelty-gated-attention
trust-remote-code
custom_code
Instructions to use User01110/tinyLM-8M-exp with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use User01110/tinyLM-8M-exp with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="User01110/tinyLM-8M-exp", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("User01110/tinyLM-8M-exp", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use User01110/tinyLM-8M-exp with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "User01110/tinyLM-8M-exp" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "User01110/tinyLM-8M-exp", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/User01110/tinyLM-8M-exp
- SGLang
How to use User01110/tinyLM-8M-exp 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 "User01110/tinyLM-8M-exp" \ --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": "User01110/tinyLM-8M-exp", "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 "User01110/tinyLM-8M-exp" \ --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": "User01110/tinyLM-8M-exp", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use User01110/tinyLM-8M-exp with Docker Model Runner:
docker model run hf.co/User01110/tinyLM-8M-exp
Use explicit causal attention for stable remote inference
Browse files
modeling_tinyqwen3_novelty.py
CHANGED
|
@@ -89,6 +89,19 @@ def apply_rope(x, cos, sin):
|
|
| 89 |
return (x * cos.to(dtype=x.dtype)) + (rotate_half(x) * sin.to(dtype=x.dtype))
|
| 90 |
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
class MathNoveltyGate(nn.Module):
|
| 93 |
def __init__(self, head_dim, floor=0.05):
|
| 94 |
super().__init__()
|
|
@@ -141,7 +154,7 @@ class NoveltyGQA(nn.Module):
|
|
| 141 |
k = apply_rope(k, cos, sin)
|
| 142 |
k = k.repeat_interleave(self.kv_repeat, dim=1)
|
| 143 |
v = v.repeat_interleave(self.kv_repeat, dim=1)
|
| 144 |
-
heads =
|
| 145 |
heads = self.novelty(heads)
|
| 146 |
out = heads.transpose(1, 2).contiguous().view(bsz, seq_len, self.dim)
|
| 147 |
return self.o_proj(out)
|
|
|
|
| 89 |
return (x * cos.to(dtype=x.dtype)) + (rotate_half(x) * sin.to(dtype=x.dtype))
|
| 90 |
|
| 91 |
|
| 92 |
+
def causal_attention(q, k, v):
|
| 93 |
+
scores = (q.float() @ k.float().transpose(-2, -1)) / (q.size(-1) ** 0.5)
|
| 94 |
+
causal_mask = torch.ones(
|
| 95 |
+
scores.size(-2),
|
| 96 |
+
scores.size(-1),
|
| 97 |
+
dtype=torch.bool,
|
| 98 |
+
device=scores.device,
|
| 99 |
+
).triu(1)
|
| 100 |
+
scores = scores.masked_fill(causal_mask, torch.finfo(scores.dtype).min)
|
| 101 |
+
probs = F.softmax(scores, dim=-1).to(dtype=v.dtype)
|
| 102 |
+
return probs @ v
|
| 103 |
+
|
| 104 |
+
|
| 105 |
class MathNoveltyGate(nn.Module):
|
| 106 |
def __init__(self, head_dim, floor=0.05):
|
| 107 |
super().__init__()
|
|
|
|
| 154 |
k = apply_rope(k, cos, sin)
|
| 155 |
k = k.repeat_interleave(self.kv_repeat, dim=1)
|
| 156 |
v = v.repeat_interleave(self.kv_repeat, dim=1)
|
| 157 |
+
heads = causal_attention(q, k, v)
|
| 158 |
heads = self.novelty(heads)
|
| 159 |
out = heads.transpose(1, 2).contiguous().view(bsz, seq_len, self.dim)
|
| 160 |
return self.o_proj(out)
|