Repository navigation
Fix regressions from security PRs #4042, #4044, and #4045 - #4062
Conversation
Summary of ChangesHello @danielhanchen, 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 consolidates and corrects several security-related changes previously discussed in separate PRs. The primary goal is to enhance the security and stability of the chat template formatting and import fix mechanisms, ensuring runtime behavior is preserved while mitigating potential vulnerabilities. The changes include refactoring dynamic code execution to safer alternatives, improving data validation, and refining conditional workarounds for external libraries. Highlights
🧠 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
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 provides a comprehensive set of fixes for regressions and security vulnerabilities. The removal of exec() and subprocess.Popen(shell=True) calls significantly improves security by eliminating potential code and command injection vectors. The new implementations using closures and argument lists are much safer and more readable. Additionally, the PR includes important correctness fixes, such as preserving 0 values in optional prompt blocks, validating batch lengths, and making the vLLM PDL workaround more robust. The new tests are thorough and provide excellent coverage for these changes. I have one minor suggestion for improving type checking style.
| formatter_templates = [] | ||
|
|
||
| for j, optional_prompt in enumerate(final_optional_prompts): | ||
| if type(optional_prompt) is str: |
There was a problem hiding this comment.
It's generally better to use isinstance() for type checking instead of type(). isinstance() is more robust as it correctly handles subclasses. This also aligns with Python's best practices (like PEP 8) and the style used in other parts of the codebase.
| if type(optional_prompt) is str: | |
| if isinstance(optional_prompt, str): |
…nslothai#4045 (unslothai#4062) * Fix security-regression fallout in chat templates and PDL patching * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Drop security regression test files from PR scope * Apply suggestion from @danielhanchen --------- Co-authored-by: Daniel Hanchen <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
This consolidates and corrects the security-related changes discussed in #4042, #4044, and #4045 while preserving runtime behavior.
What changed
to_sharegptformatter no longer usesexecand now uses a closure-based formatter.[[...]]block gating now treats onlyNoneand empty string as missing, so values like0are preserved.to_sharegptnow validates batch length alignment between merged input and output columns before zipping.shell=Falseand preserves apostrophes in prompts.fix_vllm_pdl_blackwellnow skips workaround atvLLM >= 0.13.2.vllm.lora.ops.triton_ops.*modules that exposesupports_pdl.Validation
Validated by executing both full notebooks that use
to_sharegpt:nb/Llama3_(8B)-Ollama.ipynbnb/Kaggle-Llama3_(8B)-Ollama.ipynbBoth completed
to_sharegptconversion, training, inference, and GGUF export paths.Notes
This PR is intended to supersede the behavior changes proposed in #4042, #4044, and #4045 with a single maintainable patch set.