[fix & feature] fix weight update from distributed and extend sample fields#548
[fix & feature] fix weight update from distributed and extend sample fields#548guapisolo wants to merge 9 commits intoradixark:mainfrom
Conversation
Summary of ChangesHello @guapisolo, 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 synchronizes internal features and bug fixes, primarily focusing on enhancing the robustness and flexibility of distributed training and evaluation workflows. Key improvements include more granular control over quantization ignore rules, refined synchronization mechanisms for distributed weight updates, and the introduction of per-sample and per-dataset custom generation function paths for more adaptable evaluation strategies. These changes aim to prevent the accidental removal of experimental features and ensure stable operation in complex distributed environments. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces several features, such as the ability to specify custom generation functions on a per-sample or per-dataset basis, improved distributed weight updates with better synchronization, and enhanced logging. However, it introduces a critical security flaw by allowing arbitrary Python functions to be loaded and executed based on paths specified in evaluation configurations or datasets. This feature requires a redesign to use a strict allow-list of permitted functions or a more secure plugin architecture. Additionally, a potential issue exists in quantizer_compressed_tensors.py where the logic for ignoring parameters with regex rules might lead to incorrect behavior.
| custom_func_path = getattr(sample, "generate_function_path", None) or args.custom_generate_function_path | ||
|
|
||
| if custom_func_path is not None: | ||
| custom_generate_func = load_function(custom_func_path) |
There was a problem hiding this comment.
The introduction of sample.generate_function_path as a source for load_function creates a critical Arbitrary Code Execution (ACE) vulnerability. This attribute can be populated from evaluation dataset configurations (dataset_cfg.custom_generate_function_path) or potentially from the dataset itself if it is loaded via Sample.from_dict. Since load_function dynamically imports and returns any attribute from any module in the Python path, and the resulting object is subsequently called (lines 224, 226), an attacker who can influence the evaluation configuration or the dataset can execute arbitrary Python code on the worker nodes. This is particularly dangerous in environments where datasets or configurations are shared or sourced from external repositories.
| sample.index = sample_index | ||
| sample_index += 1 | ||
| sample.metadata = dataset_cfg.inject_metadata(getattr(sample, "metadata", None)) | ||
| sample.generate_function_path = getattr(dataset_cfg, "custom_generate_function_path", None) |
There was a problem hiding this comment.
Setting sample.generate_function_path directly from dataset_cfg without validation allows the evaluation configuration to dictate which Python functions are executed during the rollout process. If the evaluation configuration is sourced from an untrusted or user-supplied file, this leads to arbitrary code execution.
| for name, param in converted_named_params: | ||
| is_ignored = any((r.startswith("re:") and re.match(r[3:], name)) or r == name for r in ignore_rules) | ||
| is_ignored = any( | ||
| (r.startswith("re:") and re.match(r[3:], name)) or r == name or name.startswith(r) for r in ignore_rules |
There was a problem hiding this comment.
The current logic for checking ignore rules has a potential issue. A rule prefixed with re: is intended to be a regular expression, but it's also being checked as a prefix with name.startswith(r). This could lead to unintended matches. For example, if an ignore rule is "re:model.layers" and a parameter is named "re:model.layers.attention", it would be incorrectly ignored due to the prefix match, even if the regex itself doesn't match.
To fix this, we should separate the logic for regex rules and plain string rules (exact match or prefix).
| (r.startswith("re:") and re.match(r[3:], name)) or r == name or name.startswith(r) for r in ignore_rules | |
| (re.match(r[3:], name) if r.startswith("re:") else (r == name or name.startswith(r))) for r in ignore_rules |
a6083d7 to
70124f2
Compare
27b0313 to
0d168ff
Compare
49ebac9 to
aa96b87
Compare
32f1c3a to
8be35f6
Compare
Co-Authored-By: miles-code-angel <miles.pr.bot@gmail.com>
Co-Authored-By: miles-code-angel <miles.pr.bot@gmail.com>
Co-Authored-By: miles-code-angel <miles.pr.bot@gmail.com>
Co-Authored-By: miles-code-angel <miles.pr.bot@gmail.com>
Tests for: prefix-matching ignore rules in quantizer, new generate_function_path field on Sample and EvalDatasetConfig, and per-sample custom generate function path priority logic.
The _create_with_all_fields check requires all Sample fields to be explicitly provided. Adding the new generate_function_path field to _merge_sample_pair to fix 6 failing tests.
These only tested dataclass field defaults with no real logic, adding maintenance burden without value.
Consolidate 14 tests into 8 by merging single-param cases into one parametrize, extracting _is_ignored helper, and removing tests for pre-existing behavior unrelated to this change.
8be35f6 to
459a9d4
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Avoid experimental feature to be deleted