leejunhyeok commited on
Commit
6890108
·
verified ·
1 Parent(s): 1e90a1a

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. chat_template.jinja +157 -0
  3. config.json +81 -0
  4. configuration_motif.py +294 -0
  5. generation_config.json +13 -0
  6. model-00001-of-00155.safetensors +3 -0
  7. model-00002-of-00155.safetensors +3 -0
  8. model-00003-of-00155.safetensors +3 -0
  9. model-00004-of-00155.safetensors +3 -0
  10. model-00005-of-00155.safetensors +3 -0
  11. model-00006-of-00155.safetensors +3 -0
  12. model-00007-of-00155.safetensors +3 -0
  13. model-00008-of-00155.safetensors +3 -0
  14. model-00009-of-00155.safetensors +3 -0
  15. model-00010-of-00155.safetensors +3 -0
  16. model-00011-of-00155.safetensors +3 -0
  17. model-00012-of-00155.safetensors +3 -0
  18. model-00013-of-00155.safetensors +3 -0
  19. model-00014-of-00155.safetensors +3 -0
  20. model-00015-of-00155.safetensors +3 -0
  21. model-00016-of-00155.safetensors +3 -0
  22. model-00017-of-00155.safetensors +3 -0
  23. model-00018-of-00155.safetensors +3 -0
  24. model-00019-of-00155.safetensors +3 -0
  25. model-00020-of-00155.safetensors +3 -0
  26. model-00021-of-00155.safetensors +3 -0
  27. model-00022-of-00155.safetensors +3 -0
  28. model-00023-of-00155.safetensors +3 -0
  29. model-00024-of-00155.safetensors +3 -0
  30. model-00025-of-00155.safetensors +3 -0
  31. model-00026-of-00155.safetensors +3 -0
  32. model-00027-of-00155.safetensors +3 -0
  33. model-00028-of-00155.safetensors +3 -0
  34. model-00029-of-00155.safetensors +3 -0
  35. model-00030-of-00155.safetensors +3 -0
  36. model-00031-of-00155.safetensors +3 -0
  37. model-00032-of-00155.safetensors +3 -0
  38. model-00033-of-00155.safetensors +3 -0
  39. model-00034-of-00155.safetensors +3 -0
  40. model-00035-of-00155.safetensors +3 -0
  41. model-00036-of-00155.safetensors +3 -0
  42. model-00037-of-00155.safetensors +3 -0
  43. model-00038-of-00155.safetensors +3 -0
  44. model-00039-of-00155.safetensors +3 -0
  45. model-00040-of-00155.safetensors +3 -0
  46. model-00041-of-00155.safetensors +3 -0
  47. model-00042-of-00155.safetensors +3 -0
  48. model-00043-of-00155.safetensors +3 -0
  49. model-00044-of-00155.safetensors +3 -0
  50. model-00045-of-00155.safetensors +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
chat_template.jinja ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- macro visible_text(content) -%}
2
+ {%- if content is string -%}
3
+ {{- content -}}
4
+ {%- elif content is iterable and content is not mapping -%}
5
+ {%- for item in content -%}
6
+ {%- if item is mapping and item.type == 'text' -%}
7
+ {{- item.text -}}
8
+ {%- elif item is string -%}
9
+ {{- item -}}
10
+ {%- endif -%}
11
+ {%- endfor -%}
12
+ {%- else -%}
13
+ {{- content -}}
14
+ {%- endif -%}
15
+ {%- endmacro -%}
16
+
17
+ {{- '<|beginoftext|>' -}}
18
+
19
+ {%- set ns = namespace(has_system=false, last_user_index=-1, last_assistant_index=-1) -%}
20
+ {%- if messages | length > 0 and messages[0].role == 'system' -%}
21
+ {%- set ns.has_system = true -%}
22
+ {%- endif -%}
23
+ {%- for m in messages -%}
24
+ {%- if m.role == 'user' -%}
25
+ {%- set ns.last_user_index = loop.index0 -%}
26
+ {%- elif m.role == 'assistant' -%}
27
+ {%- set ns.last_assistant_index = loop.index0 -%}
28
+ {%- endif -%}
29
+ {%- endfor -%}
30
+
31
+ {#- ── System / Tools block ── -#}
32
+ {%- if tools is iterable and tools | length > 0 -%}
33
+ {{- '<|startofturn|><|system|>' -}}
34
+ {{- '# Tools\n\nYou may call one or more functions to assist with the user query.\n\n' -}}
35
+ {{- 'You are provided with function signatures within <tools></tools> XML tags:\n\n<tools>' -}}
36
+ {%- for tool in tools -%}
37
+ {%- if tool.function is defined -%}
38
+ {%- set tool = tool.function -%}
39
+ {%- endif -%}
40
+ {{- '\n' ~ (tool | tojson) -}}
41
+ {%- endfor -%}
42
+ {{- '\n</tools>' -}}
43
+ {{- '\n\nFor each function call, output in JSON within <tool_call> tags:\n' -}}
44
+ {%- for tool in tools -%}
45
+ {%- if tool.function is defined -%}
46
+ {%- set tool = tool.function -%}
47
+ {%- endif -%}
48
+ {%- set _props = tool.parameters.properties if (tool.parameters is defined and tool.parameters.properties is defined) else {} -%}
49
+ {{- '\n<tool_call>{"name": "' ~ tool.name ~ '", "arguments": {' -}}
50
+ {%- set _keys = _props | list -%}
51
+ {%- for k in _keys -%}
52
+ {{- '"' ~ k ~ '": <' ~ k ~ '>' -}}
53
+ {%- if not loop.last -%}{{- ', ' -}}{%- endif -%}
54
+ {%- endfor -%}
55
+ {{- '}}</tool_call>' -}}
56
+ {%- endfor -%}
57
+ {%- if ns.has_system -%}
58
+ {{- '\n\n' ~ visible_text(messages[0].content) -}}
59
+ {%- endif -%}
60
+ {{- '<|endofturn|>' -}}
61
+ {%- elif ns.has_system -%}
62
+ {{- '<|startofturn|><|system|>' ~ visible_text(messages[0].content) ~ '<|endofturn|>' -}}
63
+ {%- endif -%}
64
+
65
+ {#- ── Conversation turns ── -#}
66
+ {%- for m in messages -%}
67
+
68
+ {#- [Fix 1] continue 대신 if/elif 체인으로 첫 system 스킵 -#}
69
+ {%- if loop.index0 == 0 and m.role == 'system' -%}
70
+ {#- already rendered above, skip -#}
71
+
72
+ {#- [Fix 2] 중간에 나오는 system 메시지도 처리 -#}
73
+ {%- elif m.role == 'system' -%}
74
+ {{- '<|startofturn|><|system|>' ~ visible_text(m.content) ~ '<|endofturn|>' -}}
75
+
76
+ {%- elif m.role == 'user' -%}
77
+ {{- '<|startofturn|><|user|>' -}}
78
+ {%- if m.references is defined and m.references -%}
79
+ {{- '<|reference|>' ~ m.references ~ '\n' -}}
80
+ {%- endif -%}
81
+ {{- visible_text(m.content) -}}
82
+ {{- '<|endofturn|>' -}}
83
+
84
+ {%- elif m.role == 'assistant' -%}
85
+ {{- '<|startofturn|><|assistant|>' -}}
86
+
87
+ {#- [순서 정책] think → plan → content → tool_calls -#}
88
+
89
+ {#- Reasoning block -#}
90
+ {%- set _content = visible_text(m.content) -%}
91
+ {%- set _reasoning = '' -%}
92
+ {%- if m.reasoning_content is string -%}
93
+ {%- set _reasoning = m.reasoning_content -%}
94
+ {%- elif '</think>' in _content -%}
95
+ {%- set _reasoning = _content.split('</think>')[0].split('<think>')[-1].strip() -%}
96
+ {%- set _content = _content.split('</think>', 1)[-1].lstrip('\n') -%}
97
+ {%- endif -%}
98
+ {%- set _has_tools = (tools is defined and tools is iterable and tools | length > 0) -%}
99
+ {%- set _emit_think = _reasoning and (_has_tools or loop.index0 == ns.last_assistant_index) -%}
100
+ {%- if _emit_think -%}
101
+ {{- '<think>' ~ _reasoning.strip() ~ '</think>' -}}
102
+ {%- endif -%}
103
+
104
+ {#- Text content -#}
105
+ {%- if _content.strip() -%}
106
+ {{- _content.strip() -}}
107
+ {%- endif -%}
108
+
109
+ {#- Tool calls — IDs are rendered for intermediate assistant turns
110
+ (context for call↔response correlation) but omitted for the last
111
+ assistant turn (prediction target — model should not learn to
112
+ generate IDs). After multi-turn data expansion, intermediate turns
113
+ become GRAY context and the last turn is GREEN. -#}
114
+ {%- if m.tool_calls is defined and m.tool_calls -%}
115
+ {%- set _is_last_assistant = (loop.index0 == ns.last_assistant_index) and not add_generation_prompt -%}
116
+ {%- for tc in m.tool_calls -%}
117
+ {%- set _tc_id = tc.id if (tc.id is defined and not _is_last_assistant) else none -%}
118
+ {%- if tc.function is defined -%}
119
+ {%- set tc = tc.function -%}
120
+ {%- endif -%}
121
+ {%- set _id_suffix = ', "id": ' ~ (_tc_id | tojson) if _tc_id is not none else '' -%}
122
+ {%- if tc.arguments is not defined or not tc.arguments or tc.arguments == "" -%}
123
+ {{- '\n<tool_call>' ~ '{"name": "' ~ tc.name ~ '", "arguments": ' ~ null ~ _id_suffix ~ '}' ~ '</tool_call>' -}}
124
+ {%- elif tc.arguments is string -%}
125
+ {{- '\n<tool_call>' ~ '{"name": "' ~ tc.name ~ '", "arguments": ' ~ tc.arguments ~ _id_suffix ~ '}' ~ '</tool_call>' -}}
126
+ {%- else -%}
127
+ {{- '\n<tool_call>' ~ '{"name": "' ~ tc.name ~ '", "arguments": ' ~ (tc.arguments | tojson) ~ _id_suffix ~ '}' ~ '</tool_call>' -}}
128
+ {%- endif -%}
129
+ {%- endfor -%}
130
+ {%- endif -%}
131
+
132
+ {{- '<|endofturn|>' -}}
133
+
134
+ {%- elif m.role == 'tool' -%}
135
+ {#- [Fix 3] loop.previtem/nextitem으로 인덱스 오버플로 제거 -#}
136
+ {%- if loop.first or loop.previtem.role != 'tool' -%}
137
+ {{- '<|startofturn|><|tool|>' -}}
138
+ {%- endif -%}
139
+ {{- '<tool_response>' ~ ({"tool_call_id": m.tool_call_id, "content": m.content} | tojson) ~ '</tool_response>' -}}
140
+ {%- if loop.last or loop.nextitem.role != 'tool' -%}
141
+ {{- '<|endofturn|>' -}}
142
+ {%- endif -%}
143
+
144
+ {%- endif -%}
145
+ {%- endfor -%}
146
+
147
+ {#- ── Generation prompt ── -#}
148
+ {%- if add_generation_prompt -%}
149
+ {{- '<|startofturn|><|assistant|>' -}}
150
+ {%- if enable_thinking is defined and not enable_thinking -%}
151
+ {{- '<think></think>' -}}
152
+ {%- else -%}
153
+ {{- '<think>' -}}
154
+ {%- endif -%}
155
+ {%- else -%}
156
+ {{- '<|endoftext|>' -}}
157
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_debug_force_load_balance": false,
3
+ "architectures": [
4
+ "MotifForCausalLM"
5
+ ],
6
+ "attention_cls": "gdla",
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_motif.MotifConfig",
10
+ "AutoModel": "modeling_motif.MotifForCausalLM",
11
+ "AutoModelForCausalLM": "modeling_motif.MotifForCausalLM"
12
+ },
13
+ "diff_v2": true,
14
+ "dtype": "bfloat16",
15
+ "elementwise_attn_output_gate": true,
16
+ "eos_token_id": 0,
17
+ "experts_top_k": 8,
18
+ "head_dim": 192,
19
+ "headwise_attn_output_gate": false,
20
+ "hidden_act": "poly_norm",
21
+ "hidden_size": 4096,
22
+ "initializer_range": 0.02,
23
+ "interleave_moe_layer_step": 1,
24
+ "intermediate_size": 12288,
25
+ "k_ratio": 1,
26
+ "kv_lora_rank": 512,
27
+ "load_balance_coeff": 0.0001,
28
+ "max_position_embeddings": 262144,
29
+ "max_window_layers": 9,
30
+ "mhc_enabled": true,
31
+ "mhc_expansion_rate": 4,
32
+ "mhc_identity_init": false,
33
+ "mhc_sinkhorn_iters": 20,
34
+ "model_type": "Motif",
35
+ "moe_intermediate_size": 1280,
36
+ "mscale": 1.0,
37
+ "n_dense_first_layers": 2,
38
+ "num_attention_heads": 80,
39
+ "num_experts": 384,
40
+ "num_hidden_layers": 53,
41
+ "num_key_value_heads": 16,
42
+ "num_noise_heads": 16,
43
+ "num_shared_experts": 1,
44
+ "output_router_logits": false,
45
+ "q_lora_rank": 1024,
46
+ "qk_rope_head_dim": 64,
47
+ "rms_norm_eps": 1e-05,
48
+ "rope_theta": 10000.0,
49
+ "route_norm": true,
50
+ "route_scale": 2.0,
51
+ "router_aux_loss_coef": 0.0,
52
+ "score_before_experts": false,
53
+ "score_func": "sigmoid",
54
+ "sliding_window": 128,
55
+ "sliding_window_pattern": "interleave",
56
+ "sliding_window_period": 4,
57
+ "swa_rope_theta": 10000.0,
58
+ "tie_word_embeddings": false,
59
+ "transformers_version": "5.7.0",
60
+ "use_cache": true,
61
+ "use_sliding_window": true,
62
+ "v_head_dim": 128,
63
+ "vocab_size": 220160,
64
+ "rope_factor": 64.0,
65
+ "original_seq_len": 4096,
66
+ "rope_scaling": {
67
+ "original_max_position_embeddings": 4096,
68
+ "factor": 64.0,
69
+ "mscale": 1.0,
70
+ "rope_type": "yarn",
71
+ "rope_theta": 10000.0,
72
+ "beta_fast": 32.0,
73
+ "beta_slow": 1.0,
74
+ "apply_yarn_scaling": false
75
+ },
76
+ "polynorm_output_scale": 0.5,
77
+ "polynorm_output_scale_per_layer": {},
78
+ "polynorm_bias_clamp": 0.5,
79
+ "hidden_clamp": 1000000.0,
80
+ "num_nextn_predict_layers": 1
81
+ }
configuration_motif.py ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers.configuration_utils import PretrainedConfig
3
+ from transformers.utils import logging
4
+
5
+ logger = logging.get_logger(__name__)
6
+
7
+
8
+ class MotifConfig(PretrainedConfig):
9
+ r"""
10
+ This is the configuration class to store the configuration of a [`MotifModel`]. It is used to instantiate a
11
+ Motif model according to the specified arguments, defining the model architecture.
12
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
13
+ documentation from [`PretrainedConfig`] for more information.
14
+ Args:
15
+ vocab_size (`int`, *optional*, defaults to 151936):
16
+ Vocabulary size of the Motif model. Defines the number of different tokens that can be represented by the
17
+ `inputs_ids` passed when calling [`MotifModel`]
18
+ hidden_size (`int`, *optional*, defaults to 4096):
19
+ Dimension of the hidden representations.
20
+ intermediate_size (`int`, *optional*, defaults to 22016):
21
+ Dimension of the MLP representations.
22
+ num_hidden_layers (`int`, *optional*, defaults to 32):
23
+ Number of hidden layers in the Transformer encoder.
24
+ num_attention_heads (`int`, *optional*, defaults to 32):
25
+ Number of attention heads for each attention layer in the Transformer encoder.
26
+ num_key_value_heads (`int`, *optional*, defaults to 32):
27
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
28
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
29
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
30
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
31
+ by meanpooling all the original heads within that group. For more details checkout [this
32
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
33
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
34
+ The non-linear activation function (function or string) in the decoder.
35
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
36
+ The maximum sequence length that this model might ever be used with.
37
+ initializer_range (`float`, *optional*, defaults to 0.02):
38
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
39
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
40
+ The epsilon used by the rms normalization layers.
41
+ use_cache (`bool`, *optional*, defaults to `True`):
42
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
43
+ relevant if `config.is_decoder=True`.
44
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
45
+ Whether the model's input and output word embeddings should be tied.
46
+ rope_theta (`float`, *optional*, defaults to 1000000.0):
47
+ The base period of the RoPE embeddings.
48
+ rope_scaling (`Dict`, *optional*):
49
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
50
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
51
+ accordingly.
52
+ Expected contents:
53
+ `rope_type` (`str`):
54
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
55
+ 'llama3'], with 'default' being the original RoPE implementation.
56
+ `factor` (`float`, *optional*):
57
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
58
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
59
+ original maximum pre-trained length.
60
+ `original_max_position_embeddings` (`int`, *optional*):
61
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
62
+ pretraining.
63
+ `attention_factor` (`float`, *optional*):
64
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
65
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
66
+ `factor` field to infer the suggested value.
67
+ `beta_fast` (`float`, *optional*):
68
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
69
+ ramp function. If unspecified, it defaults to 32.
70
+ `beta_slow` (`float`, *optional*):
71
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
72
+ ramp function. If unspecified, it defaults to 1.
73
+ `short_factor` (`List[float]`, *optional*):
74
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
75
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
76
+ size divided by the number of attention heads divided by 2
77
+ `long_factor` (`List[float]`, *optional*):
78
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
79
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
80
+ size divided by the number of attention heads divided by 2
81
+ `low_freq_factor` (`float`, *optional*):
82
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
83
+ `high_freq_factor` (`float`, *optional*):
84
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
85
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
86
+ Whether to use sliding window attention.
87
+ sliding_window (`int`, *optional*, defaults to 4096):
88
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
89
+ max_window_layers (`int`, *optional*, defaults to 28):
90
+ The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
91
+ attention_dropout (`float`, *optional*, defaults to 0.0):
92
+ The dropout ratio for the attention probabilities.
93
+ ```python
94
+ >>> from transformers import MotifModel, MotifConfig
95
+ >>> # Initializing a Motif style configuration
96
+ >>> configuration = MotifConfig()
97
+ >>> # Initializing a model from the Motif-102B style configuration
98
+ >>> model = MotifModel(configuration)
99
+ >>> # Accessing the model configuration
100
+ >>> configuration = model.config
101
+ ```"""
102
+
103
+ model_type = "Motif"
104
+ keys_to_ignore_at_inference = ["past_key_values"]
105
+
106
+ base_model_tp_plan = {
107
+ # Attention
108
+ "layers.*.self_attn.q_proj": "colwise",
109
+ "layers.*.self_attn.k_proj": "colwise",
110
+ "layers.*.self_attn.v_proj": "colwise",
111
+ "layers.*.self_attn.o_proj": "rowwise",
112
+ # Dense MLP
113
+ "layers.*.mlp.gate_proj": "colwise",
114
+ "layers.*.mlp.up_proj": "colwise",
115
+ "layers.*.mlp.down_proj": "rowwise",
116
+ # MoE experts (fused gate+up)
117
+ "layers.*.moe.experts.gate_up_proj": "packed_colwise",
118
+ "layers.*.moe.experts.down_proj": "rowwise",
119
+ # Shared experts
120
+ "layers.*.moe.shared_experts.gate_proj": "colwise",
121
+ "layers.*.moe.shared_experts.up_proj": "colwise",
122
+ "layers.*.moe.shared_experts.down_proj": "rowwise",
123
+ }
124
+
125
+ base_model_pp_plan = {
126
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
127
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
128
+ "norm": (["hidden_states"], ["hidden_states"]),
129
+ }
130
+
131
+ def __init__(
132
+ self,
133
+ vocab_size=151936,
134
+ hidden_size=4096,
135
+ intermediate_size=22016,
136
+ num_hidden_layers=32,
137
+ num_attention_heads=32,
138
+ num_key_value_heads=32,
139
+ hidden_act="silu",
140
+ max_position_embeddings=32768,
141
+ initializer_range=0.02,
142
+ rms_norm_eps=1e-6,
143
+ use_cache=True,
144
+ tie_word_embeddings=False,
145
+ rope_theta=1000000.0,
146
+ rope_scaling=None,
147
+ use_sliding_window=False,
148
+ sliding_window=4096,
149
+ max_window_layers=28,
150
+ sliding_window_pattern="interleave",
151
+ sliding_window_period=2,
152
+ attention_dropout=0.0,
153
+ # Differential Attention parameters
154
+ head_dim=None,
155
+ num_noise_heads=0,
156
+ k_ratio=1,
157
+ # MoE parameters
158
+ num_experts=0,
159
+ experts_top_k=2,
160
+ num_shared_experts=0,
161
+ interleave_moe_layer_step=0,
162
+ moe_intermediate_size=None,
163
+ score_func="softmax",
164
+ route_norm=False,
165
+ route_scale=1.0,
166
+ load_balance_coeff=None,
167
+ score_before_experts=False,
168
+ _debug_force_load_balance=False,
169
+ output_router_logits=False,
170
+ router_aux_loss_coef=0.0,
171
+ # MHC (Manifold-constrained Hyper-Connections) parameters
172
+ mhc_enabled=False,
173
+ mhc_expansion_rate=4,
174
+ mhc_identity_init=False,
175
+ mhc_sinkhorn_iters=20,
176
+ # DiffAttention V2 / Attention class
177
+ diff_v2=False,
178
+ attention_cls="basic",
179
+ # GDLA (Grouped Differential Latent Attention) parameters
180
+ q_lora_rank=0,
181
+ kv_lora_rank=0,
182
+ qk_rope_head_dim=None,
183
+ v_head_dim=None,
184
+ original_seq_len=32768,
185
+ rope_factor=1.0,
186
+ mscale=1.0,
187
+ swa_rope_theta=None,
188
+ # Attention output gating
189
+ headwise_attn_output_gate=False,
190
+ elementwise_attn_output_gate=False,
191
+ # MoE: first N layers always dense (no MoE), regardless of interleave schedule
192
+ n_dense_first_layers=0,
193
+ # MTP (Multi-Token Prediction) speculative decoding
194
+ num_nextn_predict_layers=0,
195
+ **kwargs,
196
+ ):
197
+ self.vocab_size = vocab_size
198
+ self.max_position_embeddings = max_position_embeddings
199
+ self.hidden_size = hidden_size
200
+ self.intermediate_size = intermediate_size
201
+ self.num_hidden_layers = num_hidden_layers
202
+ self.num_attention_heads = num_attention_heads
203
+ self.use_sliding_window = use_sliding_window
204
+ self.sliding_window = sliding_window if use_sliding_window else None
205
+ self.max_window_layers = max_window_layers
206
+ self.sliding_window_pattern = sliding_window_pattern
207
+ self.sliding_window_period = sliding_window_period
208
+
209
+ # for backward compatibility
210
+ if num_key_value_heads is None:
211
+ num_key_value_heads = num_attention_heads
212
+
213
+ self.num_key_value_heads = num_key_value_heads
214
+ self.hidden_act = hidden_act
215
+ self.initializer_range = initializer_range
216
+ self.rms_norm_eps = rms_norm_eps
217
+ self.use_cache = use_cache
218
+ self.rope_theta = rope_theta
219
+ self.rope_scaling = rope_scaling
220
+ self.attention_dropout = attention_dropout
221
+
222
+ # Differential Attention configuration
223
+ self.head_dim = head_dim
224
+ self.num_noise_heads = num_noise_heads
225
+ self.k_ratio = k_ratio
226
+
227
+ # MoE configuration
228
+ self.num_experts = num_experts
229
+ self.experts_top_k = experts_top_k
230
+ self.num_shared_experts = num_shared_experts
231
+ self.interleave_moe_layer_step = interleave_moe_layer_step
232
+ self.moe_intermediate_size = moe_intermediate_size if moe_intermediate_size is not None else intermediate_size
233
+ self.score_func = score_func
234
+ self.route_norm = route_norm
235
+ self.route_scale = route_scale
236
+ self.load_balance_coeff = load_balance_coeff
237
+ self.score_before_experts = score_before_experts
238
+ self._debug_force_load_balance = _debug_force_load_balance
239
+ self.output_router_logits = output_router_logits
240
+ self.router_aux_loss_coef = router_aux_loss_coef
241
+
242
+ # MHC configuration
243
+ self.mhc_enabled = mhc_enabled
244
+ self.mhc_expansion_rate = mhc_expansion_rate
245
+ self.mhc_identity_init = mhc_identity_init
246
+ self.mhc_sinkhorn_iters = mhc_sinkhorn_iters
247
+
248
+ # DiffAttention V2 / Attention class
249
+ self.diff_v2 = diff_v2
250
+ self.attention_cls = attention_cls
251
+
252
+ # GDLA parameters
253
+ self.q_lora_rank = q_lora_rank
254
+ self.kv_lora_rank = kv_lora_rank
255
+ self.qk_rope_head_dim = qk_rope_head_dim
256
+ self.v_head_dim = v_head_dim
257
+ self.original_seq_len = original_seq_len
258
+ self.rope_factor = rope_factor
259
+ self.mscale = mscale
260
+ self.swa_rope_theta = swa_rope_theta
261
+
262
+ # Attention output gating
263
+ self.headwise_attn_output_gate = headwise_attn_output_gate
264
+ self.elementwise_attn_output_gate = elementwise_attn_output_gate
265
+
266
+ # MoE dense-first layers
267
+ self.n_dense_first_layers = n_dense_first_layers
268
+
269
+ # MTP speculative decoding
270
+ self.num_nextn_predict_layers = num_nextn_predict_layers
271
+
272
+ # Validate the correctness of rotary position embeddings parameters
273
+ # BC: if there is a 'type' field, move it to 'rope_type'.
274
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
275
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
276
+ if callable(getattr(type(self), "validate_rope", None)):
277
+ self.validate_rope()
278
+
279
+ # On ROCm, torch._grouped_mm is not supported at runtime even though
280
+ # transformers auto-selects the grouped_mm expert backend for torch>=2.9.
281
+ # Force eager (for-loop) dispatch so MoE models work on ROCm.
282
+ if (
283
+ self.num_experts > 0
284
+ and hasattr(torch.version, "hip")
285
+ and torch.version.hip is not None
286
+ and "experts_implementation" not in kwargs
287
+ ):
288
+ kwargs["experts_implementation"] = "eager"
289
+
290
+ super().__init__(
291
+ tie_word_embeddings=tie_word_embeddings,
292
+ **kwargs,
293
+ )
294
+ logger.info(f" kwargs : {kwargs}")
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "pad_token_id": 0,
5
+ "eos_token_id": [0, 3, 6],
6
+ "output_attentions": false,
7
+ "output_hidden_states": false,
8
+ "transformers_version": "5.7.0",
9
+ "use_cache": true,
10
+ "do_sample": true,
11
+ "temperature": 1.0,
12
+ "top_p": 0.95
13
+ }
model-00001-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d448f19cf7d6e5deb7bc4eb33c11b6a29e3ba38ed06f36161739673d482325a
3
+ size 2474208740
model-00002-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1eb1652398b1cd781e63ba7212ba871857896d927b49a9ff039aa5d450750c8
3
+ size 336158060
model-00003-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:779acccca99ba6820889f6dfa9c975ccb0a8ef0f6850f6565543525d9f7e8b9b
3
+ size 4026531992
model-00004-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:efbdffbdc2a0b0f08b69c1b79dfdbacbc60d489d8b69d442d9b35103139ff20c
3
+ size 169438244
model-00005-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a261c05852c76d8aea3f007595914b79616bafc5d8b610871248cbe6424c66d8
3
+ size 4026531992
model-00006-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c735774006a755ba75deb7a111107133c746905878ce1682f2d6de9f66128cb
3
+ size 169438244
model-00007-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2692b0a753bbf3b43eeef9c8bc10bb01324d0c1d49dd488d13362b0f3d836b2
3
+ size 4026531992
model-00008-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da1c4e051658c8acd142485621d3e113d948d7caf99048c38b4f47d2a20fc837
3
+ size 169438244
model-00009-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f660e9baa2f5caa5ffee4b3fdd5c734c87726c6f68a51f5bf36287fb05b7adce
3
+ size 4026531992
model-00010-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08c389d5a08e7a7effef1c25d687f086dce81857b5ac51aef567514c9cb1b6f8
3
+ size 169438244
model-00011-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb2d91468b652ad09c70665e4ed9a29557deddcbf7c6cd9a70f57a59b03d87f1
3
+ size 4026531992
model-00012-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e36df01f27ef3e663552b27216fdb9a46955f4936b7e39cd246422a2a10731b
3
+ size 169438244
model-00013-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ae9f93e85aa948b05c3e3030fddf1ed10c80300db4c65061da6b522fb6f056e
3
+ size 4026531992
model-00014-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52b26ded92e96ee7dd743d35c977ffb2b2758bb5ee8a1d58f740009396ec2b45
3
+ size 169438244
model-00015-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa0724f6c5426337f429855b4c59e0bf95d8da2fca7f44e509164bf1aa317d46
3
+ size 4026531992
model-00016-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e58c2cf0ca136addd3f5c129ab6b5f2266c121a97a9256ed3198b9aad422f71
3
+ size 169438244
model-00017-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:618b62820764ac2ee205816a4efefd28b8b3b7b5c5a1ffed4d2ca3959db64e4e
3
+ size 4026531992
model-00018-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c20761c60352617d41c9277e9bd0cceabb69523ce538788c46fced0cf91ca75
3
+ size 169438396
model-00019-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d57eaf08774e881ed4ebc286292f273384b0e2a24f58a320d47e49857c96b96a
3
+ size 4026531992
model-00020-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83f8879330ec2bfb707e36d18b5183f5a588cc2a7e1cc813c0b8dc0cffb841b9
3
+ size 169438284
model-00021-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:160ca8b2a98bc7b63a9107c7e6dafbb041bc109e668c16313374773a74401f5e
3
+ size 4026531992
model-00022-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:950be62cc981471239196a31e1393c05b5c07710f8773d32f197b4002e3c111d
3
+ size 169438284
model-00023-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ca72ad4dabe121f4fde880ae081355c921a616e13481ab4cb1d091e11d30ac8
3
+ size 4026531992
model-00024-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d052825b6c7eb3d35d61bb1a7431989b84fa507a99b0c5eba9351d246178fac
3
+ size 169438284
model-00025-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64471596c543df81d52d0bf691d4ca21b28ec19f03a78774725f58846bc636b3
3
+ size 4026531992
model-00026-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:416e57726a13ba8715b6d5a5e13851ba95ae0166786883b7f50a71d9e204e6f4
3
+ size 169438284
model-00027-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b27ccdf68027deb2d89b96733f44ae02c28205957951e1d5a0ccb19d15af05f
3
+ size 4026531992
model-00028-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd66917ed5061a086da6053190b2484a49ec3012d3021ef75c03450b454886d5
3
+ size 169438284
model-00029-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:353ad9a5ed504382fd80555ead5cb247dcf9ab52060b014274af8061b82b6b15
3
+ size 4026531992
model-00030-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:449d4df572c901fd3c09afa890198bf10e96006788374475557dd958c8278cc9
3
+ size 169438284
model-00031-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c599890131f8c3bec1d4c7683a724ed80ecc3f826246d5e9b60f11eb1ac490d9
3
+ size 4026531992
model-00032-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e57ccd45eecf0809bacfd82d7ea216280206d1edc9ba48b4eba42b21be4ef2d
3
+ size 169438284
model-00033-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4e22c1094e1ea7ca8a8ab4615e8ccc5b2210c58743c796147df0072dbeb22a1
3
+ size 4026531992
model-00034-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa271bb63ac57361f39beb626681ea6ebb48fd78dd94a842d6588371adec8eb5
3
+ size 169438284
model-00035-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bedbbdf120394fe75565200234475ea4f1b29928cdba87b3a9f8a593e06dc96d
3
+ size 4026531992
model-00036-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2461806db82a88db31f2886ea5702c85e9e43e74b61941a3087c73fadbb92c34
3
+ size 169438284
model-00037-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a077ad2d9b8924da94efb1dd6691e248ee4ad1271468409fd522611b792cead1
3
+ size 4026531992
model-00038-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:989273cc306fd1e32c538fc2490db41de7927c31f71c444ab9c494ee68508ca3
3
+ size 169438284
model-00039-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7cb963f713ac084448b6fc767f15a9a3ca1b1318361f7030770afc4928f17cdb
3
+ size 4026531992
model-00040-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b8b8ab9ba70831205339498bfe49055f5194b9349f0e0cda1986b93b14fdcebb
3
+ size 169438284
model-00041-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45fcfb10ee7bfd84baa379efdcfb62aab78fc190d1a4e837de9ea77be26d5d27
3
+ size 4026531992
model-00042-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc71f5151978672b0f47de152faf30dd34628ac883c6800187ced6e09c81cfb1
3
+ size 169438284
model-00043-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38f43a3fdb639d9af510f02a3d48c66668cbe6850c9e36897eeadbc0a28a52fa
3
+ size 4026531992
model-00044-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b69854117c9f9d93fd4cb969b0b1a5e927bbe300a4530306e04335c1ccb04470
3
+ size 169438284
model-00045-of-00155.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ea007d3929f682ab85db150dffc3f1cd9753dd2420fff791d37bcca9d9a26bf
3
+ size 4026531992