Conversation
Summary of ChangesHello, 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 integrates the Qwen3.5 multi-modal model into the Twinkle framework, expanding its capabilities to handle complex multi-modal tasks. The changes involve a complete overhaul of how multi-modal inputs are processed and fed into the model, ensuring seamless operation and efficient training. A new example is provided to guide users on leveraging these new features for multi-modal model training. 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 introduces support for Qwen3.5 multi-modal models, involving significant refactoring in the template and processor components for generic multi-modal input handling, and includes a new example script for Qwen3.5 mm. A critical security vulnerability has been identified in the newly added src/twinkle/utils/vision_tools.py file: the load_mm_file function is susceptible to Server-Side Request Forgery (SSRF) and Path Traversal. This stems from fetching remote URLs and reading local files based on unvalidated user-supplied paths in multimodal messages, requiring strict validation and sanitization. Furthermore, the code review identified an incorrect import and a potential AttributeError that must be addressed, along with suggestions for enhancing the new example script and a utility function for better code quality.
I am having trouble creating individual review comments. Click here to see my feedback.
src/twinkle/model/multi_lora.py (374)
This line _module.active_adapters = _peft_model.active_adapters will likely raise an AttributeError. In this else block, _module is not an instance of PeftModel and therefore does not have the active_adapters attribute. This assignment seems incorrect and will cause a runtime error. The original module is a plain torch.nn.Module or PreTrainedModel which is being wrapped by get_peft_model.
src/twinkle/model/transformers/multi_lora_transformers.py (4)
The import from sympy.printing.pytorch import torch is incorrect. It seems you intended to import the torch library, but you are importing it from sympy. This will lead to errors as it does not provide the PyTorch library. The correct import is import torch.
import torch
src/twinkle/utils/vision_tools.py (21-29)
The load_mm_file function performs an unvalidated HTTP GET request using the path parameter if it starts with "http". Since this function is used to process images and other multimodal files from user-provided messages (e.g., in Template.preprocess_image), an attacker can provide a malicious URL to perform Server-Side Request Forgery (SSRF). This could allow the attacker to scan internal networks, access internal services, or retrieve sensitive metadata from cloud providers.
To remediate this, implement a strict allow-list of domains for remote file loading, or validate that the URL points to a trusted source. Alternatively, provide a configuration option to disable remote file loading if it's not required.
src/twinkle/utils/vision_tools.py (32-34)
The load_mm_file function allows reading arbitrary files from the local filesystem if the path parameter points to an existing file. Since this function is used to process multimodal data from user-supplied messages, an attacker can provide a local file path (e.g., ../../etc/passwd) to read sensitive files. Although the content is subsequently passed to Image.open, the file is already read into memory, and an attacker might be able to infer information about the file or exploit vulnerabilities in the image processing library.
To remediate this, restrict file access to a specific directory (e.g., a temporary upload directory) and validate that the path does not contain directory traversal sequences (e.g., ..). Alternatively, provide a configuration option to disable local file loading.
cookbook/mm/fsdp2.py (31)
The function name eval shadows a Python built-in function. This can lead to confusion and potential bugs. It's a good practice to avoid using names of built-in functions. Please rename it to evaluate and update the call on line 87 accordingly.
def evaluate(model):
cookbook/mm/fsdp2.py (57)
According to PEP 8, imports should generally be at the top of the file. Moving this import to the top level improves readability and helps static analysis tools. It also avoids the overhead of repeated import checks if the function is called multiple times. Please move this import to the top of the file.
cookbook/mm/fsdp2.py (76)
Using float('inf') is more idiomatic for initializing a variable that will hold a minimum value, making the code's intent clearer than using a magic number like 99.0.
loss_metric = float('inf')
cookbook/mm/fsdp2.py (87)
This should be updated to call the renamed evaluate function to avoid shadowing the built-in eval.
metrics = evaluate(model)
src/twinkle/utils/vision_tools.py (38)
Using assert for input validation is not robust. Asserts can be disabled with the -O flag in Python, which would remove this check in production environments. It's better to use an if check and raise a ValueError with a clear error message if the data URI format is invalid. This also allows for a more descriptive error message.
if not match_:
raise ValueError("Invalid base64 data URI format.")
PR type
PR information
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).