-
Notifications
You must be signed in to change notification settings - Fork 79
Add diffusers backend support for image generation #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ericcurtin, 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 expands the model runner's capabilities by adding support for image generation. It integrates the Hugging Face diffusers library through a new backend, which includes a Python server to process image generation requests via an OpenAI-compatible API. The changes also encompass updates to the Docker build process and model handling to properly package and deploy diffusers models, making the system more versatile for different AI tasks. 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. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 2 security issues, and left some high level feedback:
Security issues:
- Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code. (link)
- Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code. (link)
General comments:
- In
buildDiffusersModel,builder.FromSafetensorsis called even when only.binfiles are found and only the first weight file is used, which is both misleading and likely incorrect for sharded or non-safetensors diffusers models; consider using a more generic builder entry point and handling multi-part weights explicitly. - The Dockerfile copies the diffusers server into a hard-coded
python3.12site-packages path, which will break if the venv is created with a different Python minor version; consider discovering the venv’s site-packages directory dynamically or usingpython -m siteto construct this path. - The
isContainerInstallhelper in the diffusers backend is currently unused; either wire it into behavior (e.g., for conditional logging or paths) or remove it to avoid dead code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `buildDiffusersModel`, `builder.FromSafetensors` is called even when only `.bin` files are found and only the first weight file is used, which is both misleading and likely incorrect for sharded or non-safetensors diffusers models; consider using a more generic builder entry point and handling multi-part weights explicitly.
- The Dockerfile copies the diffusers server into a hard-coded `python3.12` site-packages path, which will break if the venv is created with a different Python minor version; consider discovering the venv’s site-packages directory dynamically or using `python -m site` to construct this path.
- The `isContainerInstall` helper in the diffusers backend is currently unused; either wire it into behavior (e.g., for conditional logging or paths) or remove it to avoid dead code.
## Individual Comments
### Comment 1
<location> `pkg/inference/backends/diffusers/diffusers.go:125` </location>
<code_context>
cmd := exec.Command(pythonPath, "-c", "import diffusers; print(diffusers.__version__)")
</code_context>
<issue_to_address>
**security (go.lang.security.audit.dangerous-exec-command):** Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code.
*Source: opengrep*
</issue_to_address>
### Comment 2
<location> `pkg/inference/backends/diffusers/diffusers.go:140` </location>
<code_context>
cmd := exec.Command(d.pythonPath, "-c", "import diffusers; print(diffusers.__version__)")
</code_context>
<issue_to_address>
**security (go.lang.security.audit.dangerous-exec-command):** Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code.
*Source: opengrep*
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this 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 introduces a new diffusers backend for image generation. The changes are comprehensive, including a new Dockerfile variant, modifications to the model distribution logic to handle diffusers models, and a new Python server for handling image generation requests. The implementation is well-structured. I have a few suggestions to improve robustness and code clarity. Specifically, I've pointed out a brittle path in the Dockerfile, suggested refactoring some duplicated code, proposed a simplification for model path resolution, and recommended aligning an HTTP status code with standard practices.
ba18eff to
53d23d8
Compare
This commit introduces a new diffusers backend that enables image generation capabilities in the model runner. The backend integrates with Hugging Face diffusers library to provide OpenAI-compatible image generation API endpoints. The implementation includes a new Python server component that runs as a subprocess and handles image generation requests through a Unix socket interface. The backend supports various diffusers models and provides configuration options for device selection, precision, and memory optimization features. Additionally, the Dockerfile now includes a diffusers variant with the necessary Python dependencies pre-installed. The model distribution logic has been updated to properly handle diffusers model formats with their directory structure preserved in the model bundles. Signed-off-by: Eric Curtin <[email protected]>
53d23d8 to
591ee0b
Compare
This commit introduces a new diffusers backend that enables image
generation capabilities in the model runner. The backend integrates with
Hugging Face diffusers library to provide OpenAI-compatible image
generation API endpoints.
The implementation includes a new Python server component that runs as a
subprocess and handles image generation requests through a Unix socket
interface. The backend supports various diffusers models and provides
configuration options for device selection, precision, and memory
optimization features.
Additionally, the Dockerfile now includes a diffusers variant with the
necessary Python dependencies pre-installed. The model distribution
logic has been updated to properly handle diffusers model formats with
their directory structure preserved in the model bundles.
Signed-off-by: Eric Curtin [email protected]