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
Upload modeling_trm_text_ism.py
Browse files- modeling_trm_text_ism.py +19 -5
modeling_trm_text_ism.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
| 4 |
import torch.nn.functional as F
|
|
@@ -64,17 +63,32 @@ class TRMTextISMForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 64 |
self.register_buffer("rope_cos", f.cos().view(1, 1, config.max_seq_len, -1))
|
| 65 |
self.register_buffer("rope_sin", f.sin().view(1, 1, config.max_seq_len, -1))
|
| 66 |
self.post_init()
|
| 67 |
-
|
| 68 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
def tie_weights(self, *args, **kwargs):
|
| 70 |
-
if hasattr(self, 'lm_head'):
|
|
|
|
|
|
|
| 71 |
def prepare_inputs_for_generation(self, input_ids, attention_mask=None, **kwargs):
|
| 72 |
return {"input_ids": input_ids, "attention_mask": attention_mask, "use_cache": False}
|
|
|
|
| 73 |
def forward(self, input_ids, attention_mask=None, **kwargs):
|
| 74 |
B, S = input_ids.shape
|
| 75 |
x = self.token_emb(input_ids)
|
| 76 |
m = torch.tril(torch.ones(S, S, device=input_ids.device)).bool().unsqueeze(0).expand(B, -1, -1)
|
| 77 |
-
if attention_mask is not None:
|
|
|
|
| 78 |
c, s = self.rope_cos, self.rope_sin
|
| 79 |
for _ in range(self.config.recurrence_steps):
|
| 80 |
x = self.block(x, m, c, s)
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
import torch.nn.functional as F
|
|
|
|
| 63 |
self.register_buffer("rope_cos", f.cos().view(1, 1, config.max_seq_len, -1))
|
| 64 |
self.register_buffer("rope_sin", f.sin().view(1, 1, config.max_seq_len, -1))
|
| 65 |
self.post_init()
|
| 66 |
+
|
| 67 |
+
def get_input_embeddings(self):
|
| 68 |
+
return self.token_emb
|
| 69 |
+
|
| 70 |
+
def set_input_embeddings(self, value):
|
| 71 |
+
self.token_emb = value
|
| 72 |
+
|
| 73 |
+
def get_output_embeddings(self):
|
| 74 |
+
return self.lm_head
|
| 75 |
+
|
| 76 |
+
def set_output_embeddings(self, value):
|
| 77 |
+
self.lm_head = value
|
| 78 |
+
|
| 79 |
def tie_weights(self, *args, **kwargs):
|
| 80 |
+
if hasattr(self, 'lm_head'):
|
| 81 |
+
self.lm_head.weight = self.token_emb.weight
|
| 82 |
+
|
| 83 |
def prepare_inputs_for_generation(self, input_ids, attention_mask=None, **kwargs):
|
| 84 |
return {"input_ids": input_ids, "attention_mask": attention_mask, "use_cache": False}
|
| 85 |
+
|
| 86 |
def forward(self, input_ids, attention_mask=None, **kwargs):
|
| 87 |
B, S = input_ids.shape
|
| 88 |
x = self.token_emb(input_ids)
|
| 89 |
m = torch.tril(torch.ones(S, S, device=input_ids.device)).bool().unsqueeze(0).expand(B, -1, -1)
|
| 90 |
+
if attention_mask is not None:
|
| 91 |
+
m = m & attention_mask[:, None, :].bool()
|
| 92 |
c, s = self.rope_cos, self.rope_sin
|
| 93 |
for _ in range(self.config.recurrence_steps):
|
| 94 |
x = self.block(x, m, c, s)
|