Repository navigation
feat(dspark): support GLM-5.3-Flash and selectable losses #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhouaihui
wants to merge
7
commits into
inclusionAI:main
Choose a base branch
from
zhouaihui:feat/dspark-dual-loss
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,327
−83
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e75720
feat(dspark): add selectable losses and GLM Flash training
zhouaihui aa02b0e
perf(glm): default draft training to FA4 attention
zhouaihui bf7ff11
fix(glm): validate published RoPE and reasoning fields
zhouaihui cb89f3e
fix(dspark): validate exported Draft block attention
Longxmas f6a1e8b
fix(dspark): validate GLM warm-start metadata and normalize block att…
Longxmas 24159b5
fix(dspark): honor published anchor sampling defaults
zhouaihui 07b5b17
fix(glm): default training to native cuDNN attention
zhouaihui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "architectures": [ | ||
| "DSparkDraftModel" | ||
| ], | ||
| "model_type": "qwen3_dspark", | ||
| "hidden_size": 4096, | ||
| "intermediate_size": 12288, | ||
| "head_dim": 64, | ||
| "num_hidden_layers": 5, | ||
| "num_attention_heads": 64, | ||
| "num_key_value_heads": 64, | ||
| "vocab_size": 154880, | ||
| "rms_norm_eps": 1e-05, | ||
| "max_position_embeddings": 1048576, | ||
| "rope_theta": 10000, | ||
| "num_target_layers": 6, | ||
| "target_hidden_size": 4096, | ||
| "target_num_hidden_layers": 45, | ||
| "target_layer_ids": [ | ||
| 19, | ||
| 27, | ||
| 31, | ||
| 35, | ||
| 39, | ||
| 43 | ||
| ], | ||
| "mask_token_id": 154856, | ||
| "block_size": 8, | ||
| "markov_rank": 256, | ||
| "markov_head_type": "vanilla", | ||
| "enable_confidence_head": true, | ||
| "confidence_head_with_markov": true, | ||
| "tie_word_embeddings": false, | ||
| "sliding_window": 2048, | ||
| "sliding_window_non_causal": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2026 Ant Group Co., Ltd. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Text-only conversations using the GLM-5.3-Flash checkpoint template.""" | ||
|
|
||
|
|
||
| class Glm5FlashRenderer: | ||
| CACHE_VERSION = "v2" | ||
| roles = ("system", "user", "assistant") | ||
|
|
||
| def __init__(self, tokenizer): | ||
| self.tokenizer = tokenizer | ||
| self.role_ids = {} | ||
| for role in self.roles: | ||
| marker = f"<|{role}|>" | ||
| ids = tokenizer.encode(marker, add_special_tokens=False) | ||
| if len(ids) != 1 or tokenizer.convert_ids_to_tokens(ids[0]) != marker: | ||
| raise ValueError(f"GLM tokenizer lacks its {marker} role token") | ||
| self.role_ids[ids[0]] = role | ||
|
|
||
| def get_assistant_token_ids(self): | ||
| ids = {role: token for token, role in self.role_ids.items()} | ||
| return [ids["assistant"]], [ids["user"]], 0 | ||
|
|
||
| def render( | ||
| self, messages, tools=None, *, max_seq_length, last_turn_only=False, generation_config=None | ||
| ): | ||
| if tools: | ||
| raise ValueError("GLM text training requires conversations without tools") | ||
| for msg in messages: | ||
| if ( | ||
| msg.get("role") not in self.roles | ||
| or not isinstance(msg.get("content"), str) | ||
| or msg.get("tool_calls") | ||
| ): | ||
| raise ValueError("Expected GLM system/user/assistant text messages") | ||
| for alias in ("thinking", "thinking_content", "reasoning"): | ||
| if alias in msg: | ||
| raise ValueError( | ||
| f"GLM messages must store reasoning in reasoning_content, not {alias!r}" | ||
| ) | ||
| for field in ("content", "reasoning_content"): | ||
| value = msg.get(field) | ||
| if value is None: | ||
| continue | ||
| if not isinstance(value, str): | ||
| raise ValueError(f"GLM {field} must be text") | ||
| if any(f"<|{role}|>" in value for role in self.roles): | ||
| raise ValueError("A GLM message contains a reserved role token") | ||
|
|
||
| kwargs = { | ||
| k: v | ||
| for k, v in (generation_config or {}).items() | ||
| if k in ("reasoning_effort", "clear_thinking") | ||
| } | ||
| ids = self.tokenizer.apply_chat_template( | ||
| messages, tokenize=True, add_generation_prompt=False, return_dict=False, **kwargs | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| ) | ||
| mask = [0] * len(ids) | ||
| last_assistant = 0 | ||
| supervise = False | ||
| for i, token in enumerate(ids): | ||
| role = self.role_ids.get(token) | ||
| if role is not None: | ||
| supervise = role == "assistant" | ||
| if supervise: | ||
| last_assistant = i | ||
| else: | ||
| mask[i] = int(supervise) | ||
| if last_turn_only: | ||
| mask[:last_assistant] = [0] * last_assistant | ||
| return ids[:max_seq_length], mask[:max_seq_length] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.