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) 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, 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- model.safetensors +2 -2
- modeling_trm_text_ism.py +3 -3
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5235b319424854b28c715719aad9870d4ffc4e97e986f7fe4803e1023a7e71d8
|
| 3 |
+
size 182717408
|
modeling_trm_text_ism.py
CHANGED
|
@@ -39,7 +39,7 @@ class TRMBlock(nn.Module):
|
|
| 39 |
self.res, self.n1, self.n2 = config.residual_scale, nn.RMSNorm(config.dim), nn.RMSNorm(config.dim)
|
| 40 |
self.attn, self.mlp = TRMAttention(config), SwiGLUMLP(config)
|
| 41 |
self.ag, self.mg = nn.Parameter(torch.ones(config.dim)), nn.Parameter(torch.ones(config.dim))
|
| 42 |
-
def forward(self, x, mask, c, s):
|
| 43 |
x = x + self.res * torch.sigmoid(self.ag) * self.attn(self.n1(x), mask, c, s)
|
| 44 |
return x + self.res * torch.sigmoid(self.mg) * self.mlp(self.n2(x))
|
| 45 |
|
|
@@ -57,8 +57,8 @@ class TRMTextISMForCausalLM(PreTrainedModel):
|
|
| 57 |
self.post_init()
|
| 58 |
def get_input_embeddings(self): return self.token_emb
|
| 59 |
def get_output_embeddings(self): return self.lm_head
|
| 60 |
-
def tie_weights(self): self.lm_head.weight = self.token_emb.weight
|
| 61 |
-
def forward(self, input_ids,
|
| 62 |
B, S = input_ids.shape
|
| 63 |
x, m = self.token_emb(input_ids), torch.tril(torch.ones(S, S, device=input_ids.device)).bool().unsqueeze(0).expand(B, -1, -1)
|
| 64 |
for _ in range(self.config.recurrence_steps): x = self.block(x, m, self.rope_cos, self.rope_sin)
|
|
|
|
| 39 |
self.res, self.n1, self.n2 = config.residual_scale, nn.RMSNorm(config.dim), nn.RMSNorm(config.dim)
|
| 40 |
self.attn, self.mlp = TRMAttention(config), SwiGLUMLP(config)
|
| 41 |
self.ag, self.mg = nn.Parameter(torch.ones(config.dim)), nn.Parameter(torch.ones(config.dim))
|
| 42 |
+
def forward(self, x, mask, c, s):
|
| 43 |
x = x + self.res * torch.sigmoid(self.ag) * self.attn(self.n1(x), mask, c, s)
|
| 44 |
return x + self.res * torch.sigmoid(self.mg) * self.mlp(self.n2(x))
|
| 45 |
|
|
|
|
| 57 |
self.post_init()
|
| 58 |
def get_input_embeddings(self): return self.token_emb
|
| 59 |
def get_output_embeddings(self): return self.lm_head
|
| 60 |
+
def tie_weights(self, *args, **kwargs): self.lm_head.weight = self.token_emb.weight
|
| 61 |
+
def forward(self, input_ids, **kwargs):
|
| 62 |
B, S = input_ids.shape
|
| 63 |
x, m = self.token_emb(input_ids), torch.tril(torch.ones(S, S, device=input_ids.device)).bool().unsqueeze(0).expand(B, -1, -1)
|
| 64 |
for _ in range(self.config.recurrence_steps): x = self.block(x, m, self.rope_cos, self.rope_sin)
|