Skip to content

Enhance sglang engine dumping tests in dump comparator#19681

Merged
fzyzcjy merged 608 commits intosgl-project:mainfrom
fzyzcjy:ac8420/34
Mar 2, 2026
Merged

Enhance sglang engine dumping tests in dump comparator#19681
fzyzcjy merged 608 commits intosgl-project:mainfrom
fzyzcjy:ac8420/34

Conversation

@fzyzcjy
Copy link
Copy Markdown
Collaborator

@fzyzcjy fzyzcjy commented Mar 2, 2026

Motivation

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

Remove manual JSONL parsing, SummaryRecord assertions, and _find_summary
helper. The comparator's own exit code (with --forbid-skip) already
enforces zero failures and zero skips.
… e2e test

Comma separates independent parallel axes, colon attaches a qualifier
(like partial reduction) to an axis.  The parser correctly rejects
'partial' as an unknown axis name.
Auto-dumped core fields (positions, etc.) lack dims metadata, so the
comparator cannot unshard them across TP ranks and skips them.  Instead
of --forbid-skip (which treats any skip as failure), parse the JSON
summary to assert failed==0 and passed>0.
Collect moe_dp_rank/size and attn_cp_rank/size in
_SGLangPlugin.collect_parallel_info() using existing SGLang APIs
that were previously not being dumped.
In dp_attn mode, dp_size > 1 but MLP tensors have data on all ranks.
The existing dp filter would incorrectly drop valid ranks. This adds
a `// dp:=<group_name>` syntax in dims strings that redirects dp
filtering to use `<group>_rank`/`<group>_size` fields from metadata
instead of the default `dp_rank`/`dp_size`.

- dims.py: parse_dims() strips `//` section; new extract_dp_group_alias()
- dp_utils.py: filter/extract accept dp_group_alias parameter
- bundle_comparator.py: swap dims override before dp filter, pass alias
- test_dims.py: extract_dp_group_alias, parse_dims with //, resolve_dim_names with //
- test_dp_utils.py: _extract_dp_info and filter with dp_group_alias param
- test_entrypoint.py: E2E tests for dp alias noop, override-dims alias, real alias filtering
Assert that sglang_parallel_info in dump metadata contains the
newly added moe_dp_rank/size and attn_cp_rank/size fields alongside
the existing tp_rank/size.
Check every group (tp, pp, moe_ep, moe_tp, moe_dp, attn_tp,
attn_dp, local_attn_dp, attn_cp, enable_dp_attention) rather than
only the newly added ones.
The first two tests now model the realistic scenario where dp_size=2
with one empty rank (attention-style DP), while // dp:=moe_dp redirects
dp filtering to use the alias group. This avoids the aligner failure
that occurs when 2 replicated non-empty items reach it without sharding.
- test_dp_alias_absent_group_noop: single rank with dp_size=1, verifies
  // syntax doesn't break comparison
- test_dp_alias_via_override_dims: uses moe_dp_rank/moe_dp_size fields
  so override-dims with // dp:=moe_dp triggers real alias-based filtering
parse_dims() now returns DimsSpec (dims + dp_group_alias) instead of
list[DimSpec]. This removes the separate extract_dp_group_alias()
public API and keeps dp group alias extraction as an internal detail
of the parsing step.
# is more natural as an annotation/pragma marker and avoids ambiguity
with URL fragments or division operators.
… control

Instead of all-or-nothing --forbid-skip, --allow-skip-pattern accepts a
regex: tensor names matching the pattern are allowed to skip (e.g. core
auto-dump fields like positions/seq_lens that lack dims metadata at TP>1).
Default '.*' allows all skips; '^$' forbids all (equivalent to old --forbid-skip).
Replace scattered print_record() calls with a centralized report_sink
singleton that tees output to both stdout and an auto-generated JSONL
report file. This eliminates output_format parameter threading through
the call chain.

- Add ReportSink class with configure/add/close lifecycle
- Add --report-path and --no-report CLI arguments
- Default report path: <target-path>/comparator_report.jsonl
- Remove output_format from emit_display_records, _consume_comparison_records, WarningSink
- Add TestReportOutput test class and conftest autouse fixture for isolation
- Report path now printed via report_sink.add(ReportPathRecord(...))
  so it respects json/text output format
- --no-report removed; pass --report-path '' to disable instead
fzyzcjy added 21 commits March 1, 2026 12:56
h(tp:partial) -> h[tp:partial], s(cp) -> s[cp]
… fix parse_dims().dims in reduce tests"

This reverts commit d5480c8.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors and enhances the SGLang engine's debug comparator. The core changes revolve around a new, more robust dimension specification system that improves how tensor dimensions are parsed and aligned, particularly for complex sharding and fusion scenarios. This also includes a migration to a more comprehensive logging system and more flexible data parallel filtering, ensuring the comparator can handle a wider range of debugging needs with greater precision and clarity.

Highlights

  • Dimension Specification Refactoring: Introduced a new dims_spec module to replace the older dims module, providing a more powerful and flexible way to define and parse tensor dimensions, including support for fused dimensions (e.g., (a*b)) and explicit replicated axes.
  • Enhanced Axis Alignment: The axis alignment logic was overhauled to leverage the new dimension specification, enabling more precise handling of dimension matching, ordering, and conflicts, especially for fused and squeeze dimensions.
  • Improved Data Parallel Filtering: The data parallel utility functions now support dp_group_alias, allowing for more flexible filtering of data parallel ranks based on custom group names.
  • Comprehensive Logging System: Replaced the previous warning sink with a new log_sink that supports distinct error and info log levels, providing more granular feedback during comparisons.
  • Removed Obsolete Code: The axis_swapper.py module and the old dims.py module were removed, as their functionalities have been integrated or superseded by the new dims_spec system.
  • CLI Argument Presets: Added support for CLI argument presets, simplifying common comparator configurations and improving usability.
  • Refined Exit Code Logic: The comparator's exit code determination now accounts for allowed skipped and failed comparisons, offering more control over CI/CD integration.
  • Expanded Dumper Parallel Info: The dumper now collects more detailed parallel information, including MOE data parallel and attention checkpoint parallel ranks and sizes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/srt/debug_utils/comparator/init.py
    • Renamed ComparisonRecord to TensorComparisonRecord for clarity.
    • Updated model_rebuild() call to use the new TensorComparisonRecord.
  • python/sglang/srt/debug_utils/comparator/aligner/axis_aligner.py
    • Updated imports from dims to dims_spec and warning_sink to log_sink.
    • Refactored dimension alignment logic by replacing _resolve_target_order and _build_pattern with new functions _semantic_names_match, _expand_and_skip_squeeze, _build_canonical_order, and _build_side_pattern to support fused dimensions and more robust matching.
    • Added a ValueError check for invalid side arguments in execute_axis_aligner_plan.
  • python/sglang/srt/debug_utils/comparator/aligner/axis_swapper.py
    • Removed the entire file, as its functionality was absorbed or superseded by the new dimension alignment logic.
  • python/sglang/srt/debug_utils/comparator/aligner/entrypoint/planner.py
    • Updated imports from dims to dims_spec.
    • Modified compute_per_step_sub_plans to use DimsSpec and pass explicit_replicated_axes to compute_unsharder_plan.
  • python/sglang/srt/debug_utils/comparator/aligner/reorderer/executor.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/aligner/reorderer/planner.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/aligner/token_aligner/concat_steps/executor.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/aligner/token_aligner/entrypoint.py
    • Removed unused argparse import.
    • Replaced GeneralWarning with InfoLog and warning_sink with log_sink.
    • Updated compute_maybe_token_aligner_result and _build_smart_result to accept dir_pair and token_aligner_mode directly.
  • python/sglang/srt/debug_utils/comparator/aligner/token_aligner/smart/aux_loader.py
    • Updated imports from dims to dims_spec.
    • Replaced GeneralWarning with ErrorLog and InfoLog, and warning_sink with log_sink.
  • python/sglang/srt/debug_utils/comparator/aligner/token_aligner/smart/aux_plugins.py
    • Updated imports from dims to dims_spec.
    • Replaced GeneralWarning with InfoLog and warning_sink with log_sink.
    • Updated infer_cp_sharded_dims to use the new bracket syntax [] for dimension modifiers.
  • python/sglang/srt/debug_utils/comparator/aligner/token_aligner/smart/executor.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/aligner/token_aligner/smart/types.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/aligner/unsharder/executor.py
    • Updated imports from dims to dims_spec.
    • Refactored _verify_replicated_group to use a new helper _check_replicated_pair and made diff optional in ReplicatedCheckResult.
  • python/sglang/srt/debug_utils/comparator/aligner/unsharder/parallel_info.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/aligner/unsharder/planner.py
    • Updated imports from dims to dims_spec.
    • Modified compute_unsharder_plan to accept explicit_replicated_axes and use spec.sanitized_name.
    • Added _validate_explicit_replicated for robust validation of replicated axes.
  • python/sglang/srt/debug_utils/comparator/aligner/unsharder/types.py
    • Updated imports from dims to dims_spec.
  • python/sglang/srt/debug_utils/comparator/bundle_comparator.py
    • Updated imports from dims to dims_spec and warning_sink to log_sink.
    • Renamed ComparisonRecord, GeneralWarning, NonTensorRecord, SkipRecord to their *ComparisonRecord and *Log counterparts.
    • Modified compare_bundle_pair to accept dir_pair instead of separate paths and handle error/info logging via _split_logs.
    • Updated DP filtering logic in _compare_bundle_pair_inner to use dp_group_alias.
  • python/sglang/srt/debug_utils/comparator/dims.py
    • Removed the entire file, as its functionality was replaced by the new dims_spec package.
  • python/sglang/srt/debug_utils/comparator/dims_spec/init.py
    • Added new file to export components of the new dimension specification system.
  • python/sglang/srt/debug_utils/comparator/dims_spec/comment_parser.py
    • Added new file to handle parsing of comments in dimension strings for dp_group_alias and replicated_axes.
  • python/sglang/srt/debug_utils/comparator/dims_spec/dim_parser.py
    • Added new file to handle parsing of individual dimension tokens, including support for fused dimensions like (a*b).
  • python/sglang/srt/debug_utils/comparator/dims_spec/dims_parser.py
    • Added new file as the central parser for full dimension strings, integrating comment_parser and dim_parser, and handling duplicate name checks and conflicts between sharded/replicated axes.
  • python/sglang/srt/debug_utils/comparator/dims_spec/modifier_parser.py
    • Added new file to parse modifiers within dimension specifications (e.g., [tp:partial]).
  • python/sglang/srt/debug_utils/comparator/dims_spec/tensor_naming.py
    • Added new file to provide utilities for tensor naming, including find_dim_index, resolve_dim_by_name, apply_dim_names, and strip_dim_names.
  • python/sglang/srt/debug_utils/comparator/dims_spec/types.py
    • Added new file to define core types for dimension specification (e.g., DimSpec, DimsSpec, ParallelAxis, Ordering, Reduction, TokenLayout), introducing _FUSED_NAME_SEP for internal representation of fused dims.
  • python/sglang/srt/debug_utils/comparator/dp_utils.py
    • Updated filter_to_non_empty_dp_rank and _extract_dp_info to support dp_group_alias for more flexible data parallel filtering.
  • python/sglang/srt/debug_utils/comparator/entrypoint.py
    • Removed unused re import.
    • Renamed ComparisonRecord, NonTensorRecord, SkipRecord to their *ComparisonRecord counterparts.
    • Updated ConfigRecord to take config directly instead of using from_args.
    • Removed _compute_skip_keys and now use _DEFAULT_SKIP_KEYS.
    • Modified _resolve_report_path and _maybe_load_tokenizer to accept dir_pair instead of args.
    • Updated _read_df to take explicit dir_pair, start_step, end_step, and filter_pattern.
    • Introduced PRESETS and expand_preset for argument parsing.
    • Modified _consume_comparison_records to return failed_names and updated compute_exit_code to use allow_failed_pattern.
  • python/sglang/srt/debug_utils/comparator/log_sink.py
    • Added new file, replacing warning_sink.py with a more general logging mechanism (errors, infos).
  • python/sglang/srt/debug_utils/comparator/output_types.py
    • Replaced GeneralWarning with ErrorLog and InfoLog.
    • Replaced AnyWarning with AnyLog.
    • Renamed ComparisonRecord, SkipRecord, NonTensorRecord to TensorComparisonRecord, SkipComparisonRecord, NonTensorComparisonRecord.
    • Added RecordLocation to track step information.
    • Added _split_logs helper function.
    • Updated _OutputRecord to use errors and infos instead of warnings.
    • Made diff field in ReplicatedCheckResult optional.
  • python/sglang/srt/debug_utils/comparator/per_token_visualizer.py
    • Updated ComparisonRecord to TensorComparisonRecord.
  • python/sglang/srt/debug_utils/comparator/preset.py
    • Added new file, defining presets for comparator CLI arguments.
  • python/sglang/srt/debug_utils/comparator/tensor_comparator/formatter.py
    • Updated format_replicated_checks to handle optional diff in ReplicatedCheckResult.
  • python/sglang/srt/debug_utils/comparator/utils.py
    • Added auto_descend_dir for automatically finding dump directories.
    • Added compute_exit_code and _is_all_match_pattern for more robust exit code determination based on allowed skips/failures.
  • python/sglang/srt/debug_utils/comparator/warning_sink.py
    • Removed the entire file, as it was replaced by log_sink.py.
  • python/sglang/srt/debug_utils/dumper.py
    • Added moe_dp_rank, moe_dp_size, attn_cp_rank, and attn_cp_size to parallel info collection.
  • test/registered/debug_utils/comparator/aligner/entrypoint/test_executor.py
    • Updated imports from dims to dims_spec.
  • test/registered/debug_utils/comparator/aligner/entrypoint/test_planner.py
    • Updated imports from dims to dims_spec.
    • Updated dim string syntax from h(tp) to h[tp] in test cases.
  • test/registered/debug_utils/comparator/aligner/reorderer/test_executor.py
    • Updated imports from dims to dims_spec.
  • test/registered/debug_utils/comparator/aligner/reorderer/test_planner.py
    • Updated imports from dims to dims_spec.
    • Updated dim string syntax from s(cp:zigzag) to s[cp:zigzag] in test cases.
  • test/registered/debug_utils/comparator/aligner/test_axis_aligner.py
    • Updated imports from warning_sink to log_sink.
    • Updated dim string syntax from h(tp) to h[tp] in test cases.
    • Added new test cases for fused dimensions and their alignment behavior.
  • test/registered/debug_utils/comparator/aligner/test_axis_swapper.py
    • Removed the entire file.
  • test/registered/debug_utils/comparator/aligner/token_aligner/test_aux_loader.py
    • Updated imports from output_types and warning_sink to use LogSink, ErrorLog, and InfoLog.
    • Updated dim string syntax from t(cp:zigzag) to t[cp:zigzag] in test cases.
  • test/registered/debug_utils/comparator/aligner/token_aligner/test_aux_plugins.py
    • Updated imports from dims to dims_spec.
    • Updated dim string syntax from t(cp:zigzag) to t[cp:zigzag] in test cases.
  • test/registered/debug_utils/comparator/aligner/token_aligner/test_executor.py
    • Updated imports from dims to dims_spec.
  • test/registered/debug_utils/comparator/aligner/token_aligner/test_planner.py
    • Updated imports from dims to dims_spec.
  • test/registered/debug_utils/comparator/aligner/unsharder/test_executor.py
    • Updated imports from dims to dims_spec.
    • Updated _name_tensors to use spec.sanitized_name.
    • Updated dim string syntax from h(tp) to h[tp] and added explicit replicated axes declarations in test cases.
  • test/registered/debug_utils/comparator/aligner/unsharder/test_parallel_info.py
    • Updated imports from dims to dims_spec.
  • test/registered/debug_utils/comparator/aligner/unsharder/test_planner.py
    • Updated imports from dims to dims_spec.
    • Updated dim string syntax from h(tp) to h[tp] and added explicit replicated axes declarations in test cases.
    • Added new test cases for fused dimensions in unsharder planning.
  • test/registered/debug_utils/comparator/conftest.py
    • Added filterwarnings for pytest.PytestConfigWarning and UserWarning related to named tensors.
  • test/registered/debug_utils/comparator/dims_spec/test_dim_parser.py
    • Added new test file for dim_parser functionality, including fused dimensions.
  • test/registered/debug_utils/comparator/dims_spec/test_dims_parser.py
    • Added new test file for dims_parser functionality, including comment parsing and replicated axes.
  • test/registered/debug_utils/comparator/dims_spec/test_tensor_naming.py
    • Added new test file for tensor_naming utilities.
  • test/registered/debug_utils/comparator/dims_spec/test_types.py
    • Added new test file for dims_spec types.
  • test/registered/debug_utils/comparator/tensor_comparator/test_formatter.py
    • Removed redundant markers from diff output in test assertions.
  • test/registered/debug_utils/comparator/tensor_comparator/test_types.py
    • Updated ComparisonRecord to TensorComparisonRecord and GeneralWarning to ErrorLog/InfoLog.
    • Updated test cases to reflect new logging and record types.
  • test/registered/debug_utils/comparator/test_bundle_comparator.py
    • Updated imports from output_types and warning_sink to use LogSink and ErrorLog.
    • Updated test cases to reflect new logging and record types.
  • test/registered/debug_utils/comparator/test_dims.py
    • Removed the entire file.
  • test/registered/debug_utils/comparator/test_dp_utils.py
    • Added new test cases for dp_group_alias functionality in _extract_dp_info and filter_to_non_empty_dp_rank.
  • test/registered/debug_utils/comparator/test_log_sink.py
    • Renamed from test_warning_sink.py.
    • Updated test cases to use LogSink, ErrorLog, and InfoLog.
  • test/registered/debug_utils/comparator/test_manually_verify.py
    • Updated ComparisonRecord to TensorComparisonRecord in test cases.
  • test/registered/debug_utils/comparator/test_meta_overrider.py
    • Updated dim string syntax from v(tp) to v[tp] in test cases.
  • test/registered/debug_utils/comparator/test_model_validation.py
    • Updated imports from dims to dims_spec and output_types to use ErrorLog, NonTensorComparisonRecord, SkipComparisonRecord, TensorComparisonRecord.
    • Updated test cases to reflect new logging and record types.
  • test/registered/debug_utils/comparator/test_output_types.py
    • Added new test file for output_types functionality, specifically _split_logs and LogRecord text formatting.
  • test/registered/debug_utils/comparator/test_per_token_visualizer.py
    • Updated ComparisonRecord to TensorComparisonRecord in test cases.
  • test/registered/debug_utils/comparator/test_preset.py
    • Added new test file for preset expansion logic.
  • test/registered/debug_utils/comparator/test_utils.py
    • Added new test cases for compute_exit_code and auto_descend_dir.
  • test/registered/debug_utils/source_patcher/test_code_patcher.py
    • Updated register_cuda_ci to include nightly=True.
  • test/registered/debug_utils/source_patcher/test_dumper_integration.py
    • Updated register_cuda_ci to include nightly=True.
  • test/registered/debug_utils/source_patcher/test_source_editor.py
    • Updated register_cuda_ci to include nightly=True.
  • test/registered/debug_utils/test_dumper.py
    • Added assertions to verify the presence of new parallel info keys (moe_dp_rank, attn_cp_rank, etc.) in dumper metadata.
  • test/registered/debug_utils/test_engine_dumper_comparator_e2e.py
    • Updated E2E test to use Qwen3-30B-A3B (MOE model), increased est_time, changed tp values, added _FIELDS_TO_VERIFY, and introduced a separate PATCH_CONFIG_DP_ATTENTION_YAML for dp-attention tests.
    • Comparator arguments now include allow_skipped_pattern.
    • Refactored E2E tests into _run_e2e_scenario helper function.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@fzyzcjy fzyzcjy merged commit 3ebd85b into sgl-project:main Mar 2, 2026
30 of 35 checks passed
Kangyan-Zhou pushed a commit to Kangyan-Zhou/sglang that referenced this pull request Mar 4, 2026
magicYang1573 pushed a commit to magicYang1573/sglang that referenced this pull request Mar 9, 2026
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant