Skip to content

Commit d319c3d

Browse files
authored
Add support for Zaya models (#1682)
* Add support for Zaya * Create test_modeling_zaya.js * formatting
1 parent 3dc58cb commit d319c3d

8 files changed

Lines changed: 88 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,5 @@ To find compatible models on the Hub, select the "transformers.js" library tag i
451451
1. **[XLM-RoBERTa](https://huggingface.co/docs/transformers/model_doc/xlm-roberta)** (from Facebook AI), released together with the paper [Unsupervised Cross-lingual Representation Learning at Scale](https://huggingface.co/papers/1911.02116) by Alexis Conneau*, Kartikay Khandelwal*, Naman Goyal, Vishrav Chaudhary, Guillaume Wenzek, Francisco Guzmán, Edouard Grave, Myle Ott, Luke Zettlemoyer and Veselin Stoyanov.
452452
1. **[YOLOS](https://huggingface.co/docs/transformers/model_doc/yolos)** (from Huazhong University of Science & Technology) released with the paper [You Only Look at One Sequence: Rethinking Transformer in Vision through Object Detection](https://huggingface.co/papers/2106.00666) by Yuxin Fang, Bencheng Liao, Xinggang Wang, Jiemin Fang, Jiyang Qi, Rui Wu, Jianwei Niu, Wenyu Liu.
453453
1. **[Youtu-LLM](https://huggingface.co/docs/transformers/model_doc/youtu)** (from the Tencent Youtu Team) released with the paper [Youtu-LLM: Unlocking the Native Agentic Potential for Lightweight Large Language Models](https://huggingface.co/papers/2512.24618) by Junru Lu, Jiarui Qin, Lingfeng Qiao, Yinghui Li, Xinyi Dai, Bo Ke, Jianfeng He, Ruizhi Qiao, Di Yin, Xing Sun, Yunsheng Wu, Yinsong Liu, Shuangyin Liu, Mingkong Tang, Haodong Lin, Jiayi Kuang, Fanxu Meng, Xiaojuan Tang, Yunjia Xi, Junjie Huang, Haotong Yang, Zhenyi Shen, Yangning Li, Qianwen Zhang, Yifei Yu, Siyu An, Junnan Dong, Qiufeng Wang, Jie Wang, Keyu Chen, Wei Wen, Taian Guo, Zhifeng Shen, Daohai Yu, Jiahao Li, Ke Li, Zongyi Li, Xiaoyu Tan.
454+
1. **Zaya** (from Zyphra) released with the paper [ZAYA1-8B Technical Report](https://huggingface.co/papers/2605.05365) by Robert Washbourne, Rishi Iyer, Tomas Figliolia, Henry Zheng, Ryan Lorig-Roach, Sungyeon Yang, Pritish Yuvraj, Quentin Anthony, Yury Tokpanov, Xiao Yang, Ganesh Nanduru, Stephen Ebert, Praneeth Medepalli, Skyler Szot, Srivatsan Rajagopal, Alex Ong, Bhavana Mehta, Beren Millidge.
455+

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,5 @@
211211
1. **[XLM](https://huggingface.co/docs/transformers/model_doc/xlm)** (from Facebook) released together with the paper [Cross-lingual Language Model Pretraining](https://huggingface.co/papers/1901.07291) by Guillaume Lample and Alexis Conneau.
212212
1. **[XLM-RoBERTa](https://huggingface.co/docs/transformers/model_doc/xlm-roberta)** (from Facebook AI), released together with the paper [Unsupervised Cross-lingual Representation Learning at Scale](https://huggingface.co/papers/1911.02116) by Alexis Conneau*, Kartikay Khandelwal*, Naman Goyal, Vishrav Chaudhary, Guillaume Wenzek, Francisco Guzmán, Edouard Grave, Myle Ott, Luke Zettlemoyer and Veselin Stoyanov.
213213
1. **[YOLOS](https://huggingface.co/docs/transformers/model_doc/yolos)** (from Huazhong University of Science & Technology) released with the paper [You Only Look at One Sequence: Rethinking Transformer in Vision through Object Detection](https://huggingface.co/papers/2106.00666) by Yuxin Fang, Bencheng Liao, Xinggang Wang, Jiemin Fang, Jiyang Qi, Rui Wu, Jianwei Niu, Wenyu Liu.
214-
1. **[Youtu-LLM](https://huggingface.co/docs/transformers/model_doc/youtu)** (from the Tencent Youtu Team) released with the paper [Youtu-LLM: Unlocking the Native Agentic Potential for Lightweight Large Language Models](https://huggingface.co/papers/2512.24618) by Junru Lu, Jiarui Qin, Lingfeng Qiao, Yinghui Li, Xinyi Dai, Bo Ke, Jianfeng He, Ruizhi Qiao, Di Yin, Xing Sun, Yunsheng Wu, Yinsong Liu, Shuangyin Liu, Mingkong Tang, Haodong Lin, Jiayi Kuang, Fanxu Meng, Xiaojuan Tang, Yunjia Xi, Junjie Huang, Haotong Yang, Zhenyi Shen, Yangning Li, Qianwen Zhang, Yifei Yu, Siyu An, Junnan Dong, Qiufeng Wang, Jie Wang, Keyu Chen, Wei Wen, Taian Guo, Zhifeng Shen, Daohai Yu, Jiahao Li, Ke Li, Zongyi Li, Xiaoyu Tan.
214+
1. **[Youtu-LLM](https://huggingface.co/docs/transformers/model_doc/youtu)** (from the Tencent Youtu Team) released with the paper [Youtu-LLM: Unlocking the Native Agentic Potential for Lightweight Large Language Models](https://huggingface.co/papers/2512.24618) by Junru Lu, Jiarui Qin, Lingfeng Qiao, Yinghui Li, Xinyi Dai, Bo Ke, Jianfeng He, Ruizhi Qiao, Di Yin, Xing Sun, Yunsheng Wu, Yinsong Liu, Shuangyin Liu, Mingkong Tang, Haodong Lin, Jiayi Kuang, Fanxu Meng, Xiaojuan Tang, Yunjia Xi, Junjie Huang, Haotong Yang, Zhenyi Shen, Yangning Li, Qianwen Zhang, Yifei Yu, Siyu An, Junnan Dong, Qiufeng Wang, Jie Wang, Keyu Chen, Wei Wen, Taian Guo, Zhifeng Shen, Daohai Yu, Jiahao Li, Ke Li, Zongyi Li, Xiaoyu Tan.
215+
1. **Zaya** (from Zyphra) released with the paper [ZAYA1-8B Technical Report](https://huggingface.co/papers/2605.05365) by Robert Washbourne, Rishi Iyer, Tomas Figliolia, Henry Zheng, Ryan Lorig-Roach, Sungyeon Yang, Pritish Yuvraj, Quentin Anthony, Yury Tokpanov, Xiao Yang, Ganesh Nanduru, Stephen Ebert, Praneeth Medepalli, Skyler Szot, Srivatsan Rajagopal, Alex Ong, Bhavana Mehta, Beren Millidge.

packages/transformers/src/configs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ function getNormalizedConfig(config) {
216216
mapping['dim_kv'] = config.model_type === 'deepseek_v4' ? 'head_dim' : 'qk_head_dim';
217217
mapping['num_attention_heads'] = 'num_attention_heads';
218218
break;
219+
case 'zaya':
220+
mapping['num_heads'] = 'num_key_value_heads';
221+
mapping['num_layers'] = 'num_hidden_layers';
222+
mapping['hidden_size'] = 'hidden_size';
223+
mapping['dim_kv'] = 'head_dim';
224+
mapping['num_attention_heads'] = 'num_attention_heads';
225+
break;
219226

220227
// Encoder-decoder models
221228
case 't5':
@@ -420,6 +427,16 @@ export function getCacheNames(config, options) {
420427
}
421428
}
422429
return names;
430+
} else if (config.model_type === 'zaya') {
431+
const { num_hidden_layers, cca_time1 } = /** @type {any} */ (config);
432+
const stride = cca_time1 ?? 1;
433+
for (let i = 0; i < num_hidden_layers; i += stride) {
434+
names.add(`${pkv_prefix}.${i}.key`);
435+
names.add(`${pkv_prefix}.${i}.value`);
436+
names.add(`${pkv_prefix}.${i}.conv_state`);
437+
names.add(`${pkv_prefix}.${i}.shift_state`);
438+
}
439+
return names;
423440
} else if (['lfm2_vl', 'qwen3_5', 'qwen3_5_moe', 'voxtral_realtime'].includes(config.model_type)) {
424441
let subConfig;
425442
if (config.model_type === 'voxtral_realtime' && options?.session_name === 'audio_encoder') {

packages/transformers/src/models/models.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,6 @@ export * from './xlm/modeling_xlm.js';
195195
export * from './xlm_roberta/modeling_xlm_roberta.js';
196196
export * from './yolos/modeling_yolos.js';
197197
export * from './youtu/modeling_youtu.js';
198+
export * from './zaya/modeling_zaya.js';
198199

199200
export { PreTrainedModel } from './modeling_utils.js';

packages/transformers/src/models/registry.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const MODEL_MAPPING_NAMES_DECODER_ONLY = new Map([
181181
['modernbert-decoder', 'ModernBertDecoderModel'],
182182
['hunyuan_v1_dense', 'HunYuanDenseV1Model'],
183183
['youtu', 'YoutuModel'],
184+
['zaya', 'ZayaModel'],
184185
]);
185186

186187
export const MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = new Map([
@@ -329,6 +330,7 @@ export const MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = new Map([
329330
['modernbert-decoder', 'ModernBertDecoderForCausalLM'],
330331
['hunyuan_v1_dense', 'HunYuanDenseV1ForCausalLM'],
331332
['youtu', 'YoutuForCausalLM'],
333+
['zaya', 'ZayaForCausalLM'],
332334

333335
// Also image-text-to-text
334336
['phi3_v', 'Phi3VForCausalLM'],
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PreTrainedModel } from '../modeling_utils.js';
2+
3+
export class ZayaPreTrainedModel extends PreTrainedModel {}
4+
export class ZayaModel extends ZayaPreTrainedModel {}
5+
export class ZayaForCausalLM extends ZayaPreTrainedModel {}

packages/transformers/src/utils/hub.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import { apis, env } from '../env.js';
88
import { DefaultProgressCallback, dispatchCallback } from './core.js';
99
import { FileResponse } from './hub/FileResponse.js';
1010
import { FileCache } from './cache/FileCache.js';
11-
import { handleError, isValidUrl, pathJoin, isValidHfModelId, makePretrainedOptionsKey, readResponse } from './hub/utils.js';
11+
import {
12+
handleError,
13+
isValidUrl,
14+
pathJoin,
15+
isValidHfModelId,
16+
makePretrainedOptionsKey,
17+
readResponse,
18+
} from './hub/utils.js';
1219
import { getCache, tryCache } from './cache.js';
1320
import { get_file_metadata } from './model_registry/get_file_metadata.js';
1421
import { logger } from './logger.js';
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { PreTrainedTokenizer, ZayaForCausalLM } from "../../../src/transformers.js";
2+
3+
import { MAX_MODEL_LOAD_TIME, MAX_TEST_EXECUTION_TIME, MAX_MODEL_DISPOSE_TIME, DEFAULT_MODEL_OPTIONS } from "../../init.js";
4+
5+
export default () => {
6+
describe("ZayaForCausalLM", () => {
7+
const model_id = "onnx-internal-testing/tiny-random-ZayaForCausalLM";
8+
/** @type {ZayaForCausalLM} */
9+
let model;
10+
/** @type {PreTrainedTokenizer} */
11+
let tokenizer;
12+
beforeAll(async () => {
13+
model = await ZayaForCausalLM.from_pretrained(model_id, DEFAULT_MODEL_OPTIONS);
14+
tokenizer = await PreTrainedTokenizer.from_pretrained(model_id);
15+
tokenizer.padding_side = "left";
16+
}, MAX_MODEL_LOAD_TIME);
17+
18+
it(
19+
"batch_size=1",
20+
async () => {
21+
const inputs = tokenizer("hello");
22+
const outputs = await model.generate({
23+
...inputs,
24+
max_length: 10,
25+
});
26+
expect(outputs.tolist()).toEqual([[2n, 23391n, 106n, 155331n, 155331n, 155331n, 155331n, 155331n, 155331n, 155331n]]);
27+
},
28+
MAX_TEST_EXECUTION_TIME,
29+
);
30+
31+
it(
32+
"batch_size>1",
33+
async () => {
34+
const inputs = tokenizer(["hello", "hello world"], { padding: true });
35+
const outputs = await model.generate({
36+
...inputs,
37+
max_length: 10,
38+
});
39+
expect(outputs.tolist()).toEqual([
40+
[0n, 2n, 23391n, 106n, 155331n, 155331n, 155331n, 155331n, 155331n, 155331n],
41+
[2n, 23391n, 1902n, 106n, 155331n, 155331n, 155331n, 155331n, 155331n, 155331n],
42+
]);
43+
},
44+
MAX_TEST_EXECUTION_TIME,
45+
);
46+
47+
afterAll(async () => {
48+
await model?.dispose();
49+
}, MAX_MODEL_DISPOSE_TIME);
50+
});
51+
};

0 commit comments

Comments
 (0)