[fix] http_options leaking to model init & NPU tensor serialization failure over HTTP#109
[fix] http_options leaking to model init & NPU tensor serialization failure over HTTP#109kevssim wants to merge 3 commits intomodelscope:mainfrom
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 addresses two critical bugs in the HTTP serving path. It resolves an issue where 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
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 two important bug fixes: preventing http_options from leaking into model initializers and resolving a tensor serialization issue over HTTP by introducing a new forward_backward_http method. While these bug fixes are well-implemented, a critical security vulnerability was identified in the /upload_to_hub endpoint, allowing for arbitrary directory exfiltration due to a lack of path validation when the twinkle:// prefix is not used. This requires immediate attention by strictly validating and restricting all user-supplied paths to authorized directories. Additionally, there is a minor suggestion to improve code conciseness in the new _to_cpu_safe_output helper function.
| @remote_function(dispatch='slice_dp', collect='mean') | ||
| def forward_backward_http(self, *, inputs: Union[InputFeature, List[InputFeature], Trajectory, List[Trajectory]], | ||
| **kwargs): | ||
| """HTTP-safe forward/backward that materializes outputs before they leave the worker.""" | ||
| outputs = self.forward_backward(inputs=inputs, **kwargs) | ||
| return self._to_cpu_safe_output(outputs) | ||
|
|
There was a problem hiding this comment.
The forward_backward_http broke the consistency of the interface and cannot be directly modified in the transformers.py file. For special operations required by the server, you need to inherit this class and override the method. You can refer to the writing style of tinker:
twinkle/src/twinkle/server/tinker/common/transformers_model.py
Lines 91 to 99 in 3d855d5
PR type
PR information
Fix two bugs in the HTTP serving path:
1.
http_optionsleaking into model__init__http_optionswas unconditionally injected into args for all app types inServerLauncher._deploy_app(), causing it to be forwarded toQwen3ForCausalLM.__init__()and triggering aTypeError. Fixed by guarding the injection withimport_path == 'server'.2. NPU tensor serialization failure on CPU-only client
The
/forward_backwardHTTP endpoint returned raw NPU tensors, which Ray could not deserialize on the client side (no NPU available). Fixed by addingforward_backward_http, which converts all tensors/arrays to plain Python scalars/lists via_to_cpu_safe_output()before returning.