Text Generation
Transformers
Safetensors
English
trm_text_ism
trm-text
ism
recurrent-transformer
tiny-stories
conversational
custom_code
Instructions to use summerMC/TRM-textV2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use summerMC/TRM-textV2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="summerMC/TRM-textV2", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("summerMC/TRM-textV2", trust_remote_code=True, dtype="auto", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use summerMC/TRM-textV2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "summerMC/TRM-textV2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "summerMC/TRM-textV2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/summerMC/TRM-textV2
- SGLang
How to use summerMC/TRM-textV2 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 "summerMC/TRM-textV2" \ --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": "summerMC/TRM-textV2", "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 "summerMC/TRM-textV2" \ --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": "summerMC/TRM-textV2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use summerMC/TRM-textV2 with Docker Model Runner:
docker model run hf.co/summerMC/TRM-textV2
v19: Fix tied weights and lm_head loading
Browse files- config.json +0 -4
- configuration_trm_text_ism_v6.py +2 -3
- modeling_trm_text_ism_v6.py +5 -3
config.json
CHANGED
|
@@ -1,8 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"auto_map": {
|
| 3 |
-
"AutoConfig": "configuration_trm_text_ism_v6.TRMTextISMConfig",
|
| 4 |
-
"AutoModelForCausalLM": "modeling_trm_text_ism_v6.TRMTextISMForCausalLM"
|
| 5 |
-
},
|
| 6 |
"bos_token_id": null,
|
| 7 |
"dim": 768,
|
| 8 |
"dropout": 0.0,
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"bos_token_id": null,
|
| 3 |
"dim": 768,
|
| 4 |
"dropout": 0.0,
|
configuration_trm_text_ism_v6.py
CHANGED
|
@@ -2,9 +2,8 @@
|
|
| 2 |
from transformers import PretrainedConfig
|
| 3 |
class TRMTextISMConfig(PretrainedConfig):
|
| 4 |
model_type = "trm_text_ism"
|
| 5 |
-
def __init__(self, vocab_size=50257, max_seq_len=512, dim=768, n_heads=12, head_dim=64, recurrence_steps=4, mlp_ratio=2.6666666667, mlp_hidden_size=None, dropout=0.0, gate_style="stable", gate_init=-1.5, residual_scale=0.5, tie_word_embeddings=True,
|
| 6 |
-
super().__init__(tie_word_embeddings=tie_word_embeddings,
|
| 7 |
self.vocab_size, self.max_seq_len, self.dim, self.n_heads, self.head_dim = vocab_size, max_seq_len, dim, n_heads, head_dim
|
| 8 |
self.recurrence_steps, self.mlp_ratio, self.mlp_hidden_size, self.dropout = recurrence_steps, mlp_ratio, mlp_hidden_size, dropout
|
| 9 |
self.gate_style, self.gate_init, self.residual_scale = gate_style, gate_init, residual_scale
|
| 10 |
-
self.hidden_size, self.num_attention_heads, self.num_hidden_layers = dim, n_heads, 1
|
|
|
|
| 2 |
from transformers import PretrainedConfig
|
| 3 |
class TRMTextISMConfig(PretrainedConfig):
|
| 4 |
model_type = "trm_text_ism"
|
| 5 |
+
def __init__(self, vocab_size=50257, max_seq_len=512, dim=768, n_heads=12, head_dim=64, recurrence_steps=4, mlp_ratio=2.6666666667, mlp_hidden_size=None, dropout=0.0, gate_style="stable", gate_init=-1.5, residual_scale=0.5, tie_word_embeddings=True, **kwargs):
|
| 6 |
+
super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
|
| 7 |
self.vocab_size, self.max_seq_len, self.dim, self.n_heads, self.head_dim = vocab_size, max_seq_len, dim, n_heads, head_dim
|
| 8 |
self.recurrence_steps, self.mlp_ratio, self.mlp_hidden_size, self.dropout = recurrence_steps, mlp_ratio, mlp_hidden_size, dropout
|
| 9 |
self.gate_style, self.gate_init, self.residual_scale = gate_style, gate_init, residual_scale
|
|
|
modeling_trm_text_ism_v6.py
CHANGED
|
@@ -10,8 +10,11 @@ from .configuration_trm_text_ism_v6 import TRMTextISMConfig
|
|
| 10 |
def apply_rope(x, cos, sin):
|
| 11 |
B, H, S, D = x.shape
|
| 12 |
half = D // 2
|
|
|
|
|
|
|
|
|
|
| 13 |
x1, x2 = x[..., :half], x[..., half:]
|
| 14 |
-
return torch.cat([x1 *
|
| 15 |
|
| 16 |
class SwiGLUMLP(nn.Module):
|
| 17 |
def __init__(self, config):
|
|
@@ -72,12 +75,11 @@ class TRMTextISMForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 72 |
def forward(self, input_ids, attention_mask=None, response_starts=None, **kwargs):
|
| 73 |
B, S = input_ids.shape
|
| 74 |
x = self.token_emb(input_ids)
|
| 75 |
-
cos, sin = self.rope_cos[:, :, :S, :], self.rope_sin[:, :, :S, :]
|
| 76 |
mask = torch.tril(torch.ones(S, S, device=x.device)).bool().unsqueeze(0).expand(B, -1, -1)
|
| 77 |
if response_starts is not None:
|
| 78 |
for b in range(B):
|
| 79 |
rs = response_starts[b]
|
| 80 |
mask[b, :rs, :rs] = True
|
| 81 |
for _ in range(self.config.recurrence_steps):
|
| 82 |
-
x = self.block(x, mask,
|
| 83 |
return CausalLMOutputWithPast(logits=self.lm_head(self.norm(x)))
|
|
|
|
| 10 |
def apply_rope(x, cos, sin):
|
| 11 |
B, H, S, D = x.shape
|
| 12 |
half = D // 2
|
| 13 |
+
# Slice to current seq length and ensure dtypes match x
|
| 14 |
+
c = cos[:, :, :S, :].to(x.dtype)
|
| 15 |
+
s = sin[:, :, :S, :].to(x.dtype)
|
| 16 |
x1, x2 = x[..., :half], x[..., half:]
|
| 17 |
+
return torch.cat([x1 * c - x2 * s, x2 * c + x1 * s], dim=-1)
|
| 18 |
|
| 19 |
class SwiGLUMLP(nn.Module):
|
| 20 |
def __init__(self, config):
|
|
|
|
| 75 |
def forward(self, input_ids, attention_mask=None, response_starts=None, **kwargs):
|
| 76 |
B, S = input_ids.shape
|
| 77 |
x = self.token_emb(input_ids)
|
|
|
|
| 78 |
mask = torch.tril(torch.ones(S, S, device=x.device)).bool().unsqueeze(0).expand(B, -1, -1)
|
| 79 |
if response_starts is not None:
|
| 80 |
for b in range(B):
|
| 81 |
rs = response_starts[b]
|
| 82 |
mask[b, :rs, :rs] = True
|
| 83 |
for _ in range(self.config.recurrence_steps):
|
| 84 |
+
x = self.block(x, mask, self.rope_cos, self.rope_sin)
|
| 85 |
return CausalLMOutputWithPast(logits=self.lm_head(self.norm(x)))
|