Skip to content

Commit bc9cf74

Browse files
authored
Add support for HRM-Text (#1695)
1 parent 7259f84 commit bc9cf74

6 files changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ To find compatible models on the Hub, select the "transformers.js" library tag i
317317
1. **[GroupViT](https://huggingface.co/docs/transformers/model_doc/groupvit)** (from UCSD, NVIDIA) released with the paper [GroupViT: Semantic Segmentation Emerges from Text Supervision](https://huggingface.co/papers/2202.11094) by Jiarui Xu, Shalini De Mello, Sifei Liu, Wonmin Byeon, Thomas Breuel, Jan Kautz, Xiaolong Wang.
318318
1. **[Helium](https://huggingface.co/docs/transformers/main/model_doc/helium)** (from the Kyutai Team) released with the blog post [Announcing Helium-1 Preview](https://kyutai.org/2025/01/13/helium.html) by the Kyutai Team.
319319
1. **[HerBERT](https://huggingface.co/docs/transformers/model_doc/herbert)** (from Allegro.pl, AGH University of Science and Technology) released with the paper [KLEJ: Comprehensive Benchmark for Polish Language Understanding](https://www.aclweb.org/anthology/2020.acl-main.111.pdf) by Piotr Rybak, Robert Mroczkowski, Janusz Tracz, Ireneusz Gawlik.
320+
1. **[HRM-Text](https://huggingface.co/docs/transformers/model_doc/hrm_text)** (from Sapient Intelligence) released with the paper [Hierarchical Reasoning Model](https://huggingface.co/papers/2506.21734) by Guan Wang, Jin Li, Yuhao Sun, Xing Chen, Changling Liu, Yue Wu, Meng Lu, Sen Song, Yasin Abbasi Yadkori.
320321
1. **[Hiera](https://huggingface.co/docs/transformers/model_doc/hiera)** (from Meta) released with the paper [Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles](https://huggingface.co/papers/2306.00989) by Chaitanya Ryali, Yuan-Ting Hu, Daniel Bolya, Chen Wei, Haoqi Fan, Po-Yao Huang, Vaibhav Aggarwal, Arkabandhu Chowdhury, Omid Poursaeed, Judy Hoffman, Jitendra Malik, Yanghao Li, Christoph Feichtenhofer.
321322
1. **[Hubert](https://huggingface.co/docs/transformers/model_doc/hubert)** (from Facebook) released with the paper [HuBERT: Self-Supervised Speech Representation Learning by Masked Prediction of Hidden Units](https://huggingface.co/papers/2106.07447) by Wei-Ning Hsu, Benjamin Bolte, Yao-Hung Hubert Tsai, Kushal Lakhotia, Ruslan Salakhutdinov, Abdelrahman Mohamed.
322323
1. **[HunYuanDenseV1](https://huggingface.co/docs/transformers/model_doc/hunyuan_v1_dense)** (from Tencent) released with the paper [Hunyuan-Large: An Open-Source MoE Model with 52 Billion Activated Parameters by Tencent](https://huggingface.co/papers/2411.02265) by the Tencent team.

packages/transformers/docs/snippets/5_supported-models.snippet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
1. **[GroupViT](https://huggingface.co/docs/transformers/model_doc/groupvit)** (from UCSD, NVIDIA) released with the paper [GroupViT: Semantic Segmentation Emerges from Text Supervision](https://huggingface.co/papers/2202.11094) by Jiarui Xu, Shalini De Mello, Sifei Liu, Wonmin Byeon, Thomas Breuel, Jan Kautz, Xiaolong Wang.
7979
1. **[Helium](https://huggingface.co/docs/transformers/main/model_doc/helium)** (from the Kyutai Team) released with the blog post [Announcing Helium-1 Preview](https://kyutai.org/2025/01/13/helium.html) by the Kyutai Team.
8080
1. **[HerBERT](https://huggingface.co/docs/transformers/model_doc/herbert)** (from Allegro.pl, AGH University of Science and Technology) released with the paper [KLEJ: Comprehensive Benchmark for Polish Language Understanding](https://www.aclweb.org/anthology/2020.acl-main.111.pdf) by Piotr Rybak, Robert Mroczkowski, Janusz Tracz, Ireneusz Gawlik.
81+
1. **[HRM-Text](https://huggingface.co/docs/transformers/model_doc/hrm_text)** (from Sapient Intelligence) released with the paper [Hierarchical Reasoning Model](https://huggingface.co/papers/2506.21734) by Guan Wang, Jin Li, Yuhao Sun, Xing Chen, Changling Liu, Yue Wu, Meng Lu, Sen Song, Yasin Abbasi Yadkori.
8182
1. **[Hiera](https://huggingface.co/docs/transformers/model_doc/hiera)** (from Meta) released with the paper [Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles](https://huggingface.co/papers/2306.00989) by Chaitanya Ryali, Yuan-Ting Hu, Daniel Bolya, Chen Wei, Haoqi Fan, Po-Yao Huang, Vaibhav Aggarwal, Arkabandhu Chowdhury, Omid Poursaeed, Judy Hoffman, Jitendra Malik, Yanghao Li, Christoph Feichtenhofer.
8283
1. **[Hubert](https://huggingface.co/docs/transformers/model_doc/hubert)** (from Facebook) released with the paper [HuBERT: Self-Supervised Speech Representation Learning by Masked Prediction of Hidden Units](https://huggingface.co/papers/2106.07447) by Wei-Ning Hsu, Benjamin Bolte, Yao-Hung Hubert Tsai, Kushal Lakhotia, Ruslan Salakhutdinov, Abdelrahman Mohamed.
8384
1. **[HunYuanDenseV1](https://huggingface.co/docs/transformers/model_doc/hunyuan_v1_dense)** (from Tencent) released with the paper [Hunyuan-Large: An Open-Source MoE Model with 52 Billion Activated Parameters by Tencent](https://huggingface.co/papers/2411.02265) by the Tencent team.

packages/transformers/src/configs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ function getNormalizedConfig(config) {
223223
mapping['dim_kv'] = 'head_dim';
224224
mapping['num_attention_heads'] = 'num_attention_heads';
225225
break;
226+
case 'hrm_text':
227+
mapping['num_heads'] = 'num_key_value_heads';
228+
mapping['num_layers'] = 'num_hidden_layers';
229+
mapping['hidden_size'] = 'hidden_size';
230+
mapping['dim_kv'] = 'head_dim';
231+
mapping['num_attention_heads'] = 'num_attention_heads';
232+
break;
226233

227234
// Encoder-decoder models
228235
case 't5':
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PreTrainedModel, decoder_prepare_inputs_for_generation } from '../modeling_utils.js';
2+
import { ones_like, zeros_like } from '../../utils/tensor.js';
3+
4+
export class HrmTextPreTrainedModel extends PreTrainedModel {}
5+
export class HrmTextModel extends HrmTextPreTrainedModel {}
6+
export class HrmTextForCausalLM extends HrmTextPreTrainedModel {
7+
forward_params = ['input_ids', 'attention_mask', 'token_type_ids', 'past_key_values'];
8+
9+
prepare_inputs_for_generation(input_ids, model_inputs, generation_config) {
10+
const prepared = decoder_prepare_inputs_for_generation(this, input_ids, model_inputs, generation_config);
11+
12+
// HRM-Text can be pretrained as a PrefixLM.
13+
// token_type_ids=1 marks tokens inside the bidirectional prefix block,
14+
// and 0 marks autoregressively generated tokens.
15+
prepared.token_type_ids = (prepared.past_key_values ? zeros_like : ones_like)(prepared.input_ids);
16+
return prepared;
17+
}
18+
}

packages/transformers/src/models/models.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export * from './grounding_dino/modeling_grounding_dino.js';
7373
export * from './groupvit/modeling_groupvit.js';
7474
export * from './helium/modeling_helium.js';
7575
export * from './hiera/modeling_hiera.js';
76+
export * from './hrm_text/modeling_hrm_text.js';
7677
export * from './hubert/modeling_hubert.js';
7778
export * from './hunyuan_v1_dense/modeling_hunyuan_v1_dense.js';
7879
export * from './idefics3/modeling_idefics3.js';

packages/transformers/src/models/registry.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ const MODEL_MAPPING_NAMES_DECODER_ONLY = new Map([
182182
['hunyuan_v1_dense', 'HunYuanDenseV1Model'],
183183
['youtu', 'YoutuModel'],
184184
['zaya', 'ZayaModel'],
185+
['hrm_text', 'HrmTextModel'],
185186
]);
186187

187188
export const MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = new Map([
@@ -331,6 +332,7 @@ export const MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = new Map([
331332
['hunyuan_v1_dense', 'HunYuanDenseV1ForCausalLM'],
332333
['youtu', 'YoutuForCausalLM'],
333334
['zaya', 'ZayaForCausalLM'],
335+
['hrm_text', 'HrmTextForCausalLM'],
334336

335337
// Also image-text-to-text
336338
['phi3_v', 'Phi3VForCausalLM'],

0 commit comments

Comments
 (0)