Skip to content

Conversation

@sitatec
Copy link
Contributor

@sitatec sitatec commented Jan 15, 2026

input_info.return_result_tensor was ignored for all image generation. Outputting the tensor can be useful for post-processing (such as NSFW checking), without reloading the file from disk.

I noticed that for video models, they do not return the tensor directly; they return a map of {"video": tensor} here. I believe this is for compatibility with ComfyUI. If that's the case, we should only return the tensor and move ComfyUI-specific patterns to the ComfyUI wrapper codebase. What do you think?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sitatec, 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 enhances the flexibility of image generation pipelines by ensuring that the input_info.return_result_tensor flag is correctly honored. Previously, generated images were always saved to disk, but now, depending on the flag's value, the raw PyTorch tensor can be returned directly. This modification streamlines workflows that require immediate in-memory processing of generated images, such as for content moderation or further computational steps, by avoiding unnecessary disk I/O.

Highlights

  • Conditional Image Saving: Image generation runners (longcat_image, qwen_image, z_image) now conditionally save generated images to disk only if input_info.return_result_tensor is false.
  • Tensor Output Option: VAE decoders for longcat_image, qwen_image, and z_image now postprocess images into a PyTorch tensor (output_type="pt") if input_info.return_result_tensor is true, otherwise they output PIL images (output_type="pil").
  • Enhanced Post-processing: This change enables direct access to the generated image tensor for immediate post-processing (e.g., NSFW checks) without requiring an intermediate disk save and reload.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 correctly implements returning a tensor instead of saving an image to disk when input_info.return_result_tensor is true. The changes are consistently applied across longcat_image, qwen_image, and z_image runners and their corresponding VAE decoders. My review includes a few suggestions to improve code quality by removing redundant f-strings and to fix a potential bug in how file paths are parsed in the qwen_image runner.

logger.info(f"Image saved: {input_info.save_result_path}")
if not input_info.return_result_tensor:
if isinstance(images[0], list) and len(images[0]) > 1:
image_prefix = f"{input_info.save_result_path}".split(".")[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using .split('.') to remove a file extension is not robust as it will fail for file paths that contain dots in their directory names (e.g., /path.with.dots/image.png). It's safer to use rsplit('.', 1) to split only on the last dot. Also, the f-string is redundant.

A more robust way would be to use os.path.splitext, but that would require an import. Using rsplit is a good improvement without adding imports.

Suggested change
image_prefix = f"{input_info.save_result_path}".split(".")[0]
image_prefix = input_info.save_result_path.rsplit(".", 1)[0]

logger.info(f"Image saved: {input_info.save_result_path}")
if not input_info.return_result_tensor:
image = images[0]
image.save(f"{input_info.save_result_path}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The f-string formatting is redundant here as input_info.save_result_path is already a string. You can pass the variable directly to image.save for cleaner code.

Suggested change
image.save(f"{input_info.save_result_path}")
image.save(input_info.save_result_path)

logger.info(f"Image saved: {input_info.save_result_path}")
if not input_info.return_result_tensor:
image = images[0]
image.save(f"{input_info.save_result_path}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The f-string formatting is redundant here since input_info.save_result_path is already a string. You can simplify the code by passing the variable directly to image.save.

Suggested change
image.save(f"{input_info.save_result_path}")
image.save(input_info.save_result_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant