Skip to content

Change dump output format to dict with value and metadata#18879

Merged
fzyzcjy merged 3 commits intosgl-project:mainfrom
fzyzcjy:feat/ac8369/1
Feb 16, 2026
Merged

Change dump output format to dict with value and metadata#18879
fzyzcjy merged 3 commits intosgl-project:mainfrom
fzyzcjy:feat/ac8369/1

Conversation

@fzyzcjy
Copy link
Collaborator

@fzyzcjy fzyzcjy commented Feb 16, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fzyzcjy, 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 the debugging dumper utility to standardize its output format and improve its configurability. Dumped data is now stored as a dictionary containing both the actual value and associated metadata, making the debugging information more comprehensive. The dumper's initialization process has been made more explicit and robust, and helper functions for environment variable parsing have been introduced. These changes enhance the dumper's utility, maintainability, and testability.

Highlights

  • Dump Output Format Change: The dumper utility now saves data in a dictionary format, encapsulating the actual value under a 'value' key and including additional metadata under a 'meta' key. This enhances the information stored with each dump.
  • Dumper Initialization Refactor: The _Dumper class constructor has been refactored to accept explicit configuration parameters, improving clarity and testability. A new from_env class method is introduced to initialize the dumper from environment variables.
  • Robust Environment Variable Parsing: New utility functions, get_bool_env_var and get_int_env_var, have been added to safely parse boolean and integer values from environment variables, providing default values and handling parsing errors.
  • Enhanced Environment Variable Context Management: The temp_set_env context manager now includes an allow_sglang parameter, enabling controlled temporary modification of SGLANG_ prefixed environment variables, particularly useful for testing the dumper.
  • Updated Dumper Tests: Existing dumper tests have been updated to reflect the new initialization methods and the dictionary-based dump format. New tests specifically verify the structure and content of the dictionary output.

🧠 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/dump_comparator.py
    • Modified _load_object to extract the 'value' from the new dictionary-formatted dump files.
  • python/sglang/srt/debug_utils/dump_loader.py
    • Modified load to extract the 'value' from the new dictionary-formatted dump files.
  • python/sglang/srt/debug_utils/dumper.py
    • Refactored _Dumper.__init__ to accept explicit configuration parameters.
    • Added _Dumper.from_env class method for initializing the dumper from environment variables.
    • Updated the dump method to save data as a dictionary containing 'value' and 'meta' keys.
    • Replaced direct os.environ.get calls for integer and boolean values with new helper functions.
    • Added get_bool_env_var and get_int_env_var utility functions for robust environment variable parsing.
  • python/sglang/srt/environ.py
    • Modified temp_set_env to include an allow_sglang parameter, permitting temporary setting of SGLANG_ prefixed environment variables when explicitly allowed.
  • test/registered/debug_utils/test_dumper.py
    • Removed direct os import, favoring temp_set_env for environment variable management.
    • Imported specific dumper utility functions directly for pure function tests.
    • Added _make_test_dumper helper function for consistent dumper instantiation in tests.
    • Updated distributed tests (test_basic, test_http_enable, test_file_content_correctness, test_filter, test_write_disabled, test_save_false) to use temp_set_env and the new dumper initialization.
    • Modified _test_file_content_func to assert the new dictionary dump format, including 'value' and 'meta' keys.
    • Added TestDumpDictFormat class with tests to verify the structure and content of the new dictionary dump format.
    • Added _load_dump helper function to load the new dictionary dump format for testing.
    • Modified _find_dump_file to set a default rank of 0.
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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the dumper to save output as a dictionary containing both the value and metadata, which is a good improvement for enriching the dumped data. The changes are well-implemented across the dumper, loader, and comparator. The refactoring of the _Dumper class to separate configuration from instantiation is a nice improvement for testability. The test suite has been updated thoroughly to reflect these changes and to verify the new output format. I have one minor suggestion regarding a type hint in python/sglang/srt/environ.py.

for key in env_vars:
if key.startswith("SGLANG_") or key.startswith("SGL_"):
raise ValueError("temp_set_env should not be used for sglang env vars")
def temp_set_env(*, allow_sglang: bool = False, **env_vars: dict[str, Any]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The type hint for **env_vars is incorrect. The syntax **kwargs: dict[str, Any] is not the standard way to type keyword arguments. The type hint should specify the type of the values of the keyword arguments. Since the values are converted to strings later with str(value), Any would be an appropriate type here.

Suggested change
def temp_set_env(*, allow_sglang: bool = False, **env_vars: dict[str, Any]):
def temp_set_env(*, allow_sglang: bool = False, **env_vars: Any):

…et_env for distributed tests

- Extract _Dumper constructor to accept explicit keyword params instead of reading env vars directly
- Add from_env() classmethod as the singleton factory
- Add allow_sglang parameter to temp_set_env for SGLANG_DUMPER_* env vars
- Replace _reload_dumper hack with temp_set_env context manager in all distributed tests
@fzyzcjy
Copy link
Collaborator Author

fzyzcjy commented Feb 16, 2026

@gemini-code-assist review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully transitions the dump output format to a dictionary containing both the value and metadata, which significantly improves the utility of the debug dumps. The refactoring of the _Dumper class to use environment variable helpers and the updates to the test suite are well-implemented. However, a regression was identified in the _torch_save fallback logic for non-pickleable torch.nn.Parameter objects, which needs to be addressed to ensure that dumps do not fail silently for these types.

Comment on lines +167 to +171
output_data = {
"value": value,
"meta": dict(**full_kwargs),
}
_torch_save(output_data, str(path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The fallback logic in _torch_save (lines 174-184) is now broken for the dump call path. _torch_save expects its first argument to be a torch.nn.Parameter to handle pickling errors by falling back to .data. However, it is now being passed a dictionary output_data. If the tensor being dumped is a non-pickleable Parameter subclass, torch.save(output_data, path) will fail, but the isinstance(value, torch.nn.Parameter) check inside _torch_save will be false because value is now the dictionary wrapper. It is recommended to handle the Parameter conversion before wrapping it in the dictionary.

Suggested change
output_data = {
"value": value,
"meta": dict(**full_kwargs),
}
_torch_save(output_data, str(path))
output_data = {
"value": value.data if isinstance(value, torch.nn.Parameter) else value,
"meta": full_kwargs,
}
_torch_save(output_data, str(path))

Save each dump as {"value": tensor, "meta": {name, rank, ...}} instead
of just the raw tensor.  This co-locates metadata with the data and
lets downstream tools (dump_comparator, dump_loader) access context
without parsing filenames.

Update dump_comparator._load_object and DumpLoader.load to extract
the value from the new dict format while staying backward-compatible
with raw tensor files.
@fzyzcjy fzyzcjy merged commit 949792d into sgl-project:main Feb 16, 2026
26 of 34 checks passed
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