Repository navigation
Benchmarks - Add official-checkpoint V2-Lite FSDP training #887
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
gusui-msft
wants to merge
9
commits into
main
Choose a base branch
from
feat/deepseek-v2-lite-training-20261015
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,799
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
038a72d
Benchmarks - Add official-checkpoint V2-Lite FSDP training
gusui-msft d334677
Benchmarks - Remove the per-run V2-Lite training model cache
gusui-msft 28ececf
Benchmarks - Bound V2-Lite training cache cleanup
gusui-msft 18fc0e4
Docs - Condense V2-Lite training documentation
gusui-msft 69ad25e
Benchmarks - Move DeepSeek-V2-Lite helpers into a subpackage
gusui-msft 718f338
Benchmarks - Run DeepSeek-V2-Lite training in the SuperBench Python
gusui-msft dce81da
Docs - Simplify the DeepSeek-V2-Lite training section
gusui-msft 3ab6ee5
Benchmarks - Enforce one V2-Lite launcher and keep timeouts after fai…
gusui-msft 125697a
Docs - Qualify the V2-Lite training validation and host memory
gusui-msft 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
8 changes: 8 additions & 0 deletions
8
superbench/benchmarks/model_benchmarks/deepseek_v2_lite/__init__.py
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,8 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """DeepSeek-V2-Lite workers and helpers. | ||
|
|
||
| Workers run as ``python -m deepseek_v2_lite.<module>``, the inference ones in interpreters without SuperBench, | ||
| so every module except ``cache`` imports only the standard library and this package at load time. | ||
| """ |
60 changes: 60 additions & 0 deletions
60
superbench/benchmarks/model_benchmarks/deepseek_v2_lite/cache.py
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,60 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Bounded removal of one V2-Lite run's downloaded model cache.""" | ||
|
|
||
| import subprocess | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| from superbench.common.utils import logger | ||
|
|
||
| FAILURE_CLEANUP_GRACE_SECONDS = 60 | ||
| _REMOVE_TREE = 'import os, shutil, sys\nif os.path.exists(sys.argv[1]):\n shutil.rmtree(sys.argv[1])' | ||
|
|
||
|
|
||
| def remove_model_cache(cache: Path, deadline: float) -> None: | ||
| """Delete one run's model cache before a monotonic deadline, keeping reports and logs. | ||
|
|
||
| A missing budget, an expired deletion or a SuperBench SIGTERM raises TimeoutError. Other | ||
| filesystem errors are logged so that a validated measurement is not discarded. | ||
| """ | ||
| start = time.monotonic() | ||
| remaining = deadline - start | ||
| if remaining <= 0: | ||
| raise TimeoutError('No time remains to remove the V2-Lite model cache at {}.'.format(cache)) | ||
| try: | ||
| # A child process can be stopped and reaped at the deadline; an in-process rmtree cannot. | ||
| subprocess.run( | ||
| [sys.executable, '-c', _REMOVE_TREE, str(cache)], | ||
| timeout=remaining, | ||
| check=True, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.STDOUT, | ||
| universal_newlines=True, | ||
| ) | ||
| except subprocess.TimeoutExpired as error: | ||
| raise TimeoutError('V2-Lite model cache cleanup exceeded the deadline at {}.'.format(cache)) from error | ||
| except TimeoutError: | ||
| # The SuperBench SIGTERM handler raises TimeoutError, an OSError subclass; keep it fatal. | ||
| raise | ||
| except subprocess.CalledProcessError as error: | ||
| logger.error('Failed to remove the V2-Lite model cache %s: %s', cache, error.output or error) | ||
| return | ||
| except OSError as error: | ||
| logger.error('Failed to remove the V2-Lite model cache %s: %s', cache, error) | ||
| return | ||
| logger.info('V2-Lite model cache cleanup completed for %s in %.1f seconds.', cache, time.monotonic() - start) | ||
|
|
||
|
|
||
| def remove_model_cache_after_failure(cache: Path, deadline: float) -> None: | ||
| """Remove the cache of a failed run without replacing the run's original error. | ||
|
|
||
| Cleanup may run until the job deadline or for FAILURE_CLEANUP_GRACE_SECONDS, whichever ends later, | ||
| so a timed-out worker does not leave its checkpoint behind only because the budget is spent. | ||
| """ | ||
| try: | ||
| remove_model_cache(cache, max(deadline, time.monotonic() + FAILURE_CLEANUP_GRACE_SECONDS)) | ||
| except TimeoutError as error: | ||
| logger.error('V2-Lite model cache cleanup did not finish after a failed run: %s', error) |
52 changes: 52 additions & 0 deletions
52
superbench/benchmarks/model_benchmarks/deepseek_v2_lite/moe.py
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,52 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Stable expert dispatch for the pinned full-parameter V2-Lite training model.""" | ||
|
|
||
| import sys | ||
| from types import MethodType | ||
|
|
||
| MOE_DISPATCHES = ('official', 'stable_sorted') | ||
|
|
||
|
|
||
| def sorted_training_forward(module, hidden_states, auxiliary_apply): | ||
| """Preserve route order and every expert while avoiding repeated Boolean-index synchronizations.""" | ||
| import torch | ||
|
|
||
| original_shape = hidden_states.shape | ||
| indices, weights, auxiliary = module.gate(hidden_states) | ||
| routed = hidden_states.reshape(-1, original_shape[-1]).repeat_interleave(module.num_experts_per_tok, dim=0) | ||
| expert_ids = indices.reshape(-1) | ||
| order = torch.argsort(expert_ids, stable=True) | ||
| counts = torch.bincount(expert_ids, minlength=len(module.experts)).tolist() | ||
| segments = torch.split(routed.index_select(0, order), counts, dim=0) | ||
| outputs = torch.cat([expert(segment) for expert, segment in zip(module.experts, segments)], dim=0) | ||
| inverse = torch.empty_like(order) | ||
| inverse.scatter_(0, order, torch.arange(order.numel(), device=order.device)) | ||
| routed_output = outputs.index_select(0, inverse) | ||
| combined = (routed_output.view(*weights.shape, -1) * weights.unsqueeze(-1)).sum(dim=1) | ||
| combined = combined.to(hidden_states.dtype).view(original_shape) | ||
| combined = auxiliary_apply(combined, auxiliary) | ||
| if module.config.n_shared_experts is not None: | ||
| combined = combined + module.shared_experts(hidden_states) | ||
| return combined | ||
|
|
||
|
|
||
| def install_sorted_dispatch(model): | ||
| """Replace only the 26 pinned MoE training forwards, leaving evaluation and parameters intact.""" | ||
| modules = [module for module in model.modules() if type(module).__name__ == 'DeepseekV2MoE'] | ||
| if len(modules) != 26: | ||
| raise ValueError('Expected all 26 official MoE layers, found {}.'.format(len(modules))) | ||
| if any(module.ep_size != 1 for module in modules): | ||
| raise ValueError('Stable expert dispatch does not implement expert parallelism.') | ||
| for module in modules: | ||
| original = module.forward | ||
| auxiliary_apply = sys.modules[type(module).__module__].AddAuxiliaryLoss.apply | ||
|
|
||
| def forward(self, hidden_states, original=original, auxiliary_apply=auxiliary_apply): | ||
| if not self.training: | ||
| return original(hidden_states) | ||
| return sorted_training_forward(self, hidden_states, auxiliary_apply) | ||
|
|
||
| module.forward = MethodType(forward, module) | ||
| return len(modules) |
Oops, something went wrong.
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.