Skip to content

Fix plot_model producing empty output with rankdir=LR#22277

Open
rstar327 wants to merge 1 commit intokeras-team:masterfrom
rstar327:fix-plot-model-lr-rankdir
Open

Fix plot_model producing empty output with rankdir=LR#22277
rstar327 wants to merge 1 commit intokeras-team:masterfrom
rstar327:fix-plot-model-lr-rankdir

Conversation

@rstar327
Copy link
Contributor

Summary

Fixes plot_model producing empty/blank output when using rankdir="LR" (or "RL").

The root cause is that graphviz's splines="ortho" (orthogonal edge routing) is incompatible with horizontal layouts (rankdir="LR" / "RL"). For complex models like UNets with many skip connections, graphviz silently fails to render anything.

The fix uses splines="curved" for horizontal layouts while keeping splines="ortho" for the default vertical (TB/BT) layouts.

Fixes #21801

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rstar327, 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 resolves a critical rendering bug in the plot_model utility that caused blank outputs when attempting to visualize models with horizontal graph layouts (rankdir="LR" or "RL"). The fix intelligently adapts the Graphviz splines attribute, switching from ortho to curved for horizontal orientations, thereby ensuring complex models are correctly displayed without silent failures.

Highlights

  • Fix for plot_model empty output: Addressed an issue where plot_model produced empty or blank output when using horizontal graph layouts (rankdir="LR" or "RL").
  • Graphviz splines incompatibility: Identified that Graphviz's splines="ortho" is incompatible with horizontal layouts for complex models, leading to silent rendering failures.
  • Conditional splines setting: Implemented a fix to set splines="curved" for horizontal layouts (LR/RL) while retaining splines="ortho" for default vertical layouts (TB/BT), ensuring correct visualization.

🧠 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
  • keras/src/utils/model_visualization.py
    • Modified the model_to_dot function to conditionally set the splines attribute based on the rankdir parameter.
Activity
  • No specific activity (comments, reviews, progress) was found in the provided context.
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 effectively addresses the issue of plot_model producing empty outputs when using horizontal layouts (rankdir="LR" or "RL"). The solution to dynamically set splines="curved" for these layouts, while retaining "ortho" for vertical ones, is a pragmatic and correct fix. This change significantly improves the utility and reliability of the plot_model function for users, aligning with the Keras API design guidelines to minimize cognitive load and bake best practices into the API.

Comment on lines +260 to +261
# "ortho" splines are incompatible with horizontal (LR/RL) layouts
# in graphviz, producing empty output for complex models.
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 inline comment explaining the incompatibility between "ortho" splines and horizontal layouts is very helpful. For better discoverability and long-term maintainability, consider moving this explanation to the docstring of the rankdir parameter in the model_to_dot function. This ensures that users and future maintainers can easily find this crucial information when consulting the function's documentation.

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.02%. Comparing base (0ddf962) to head (7eece0c).

Files with missing lines Patch % Lines
keras/src/utils/model_visualization.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #22277       +/-   ##
===========================================
+ Coverage   71.44%   83.02%   +11.57%     
===========================================
  Files         594      594               
  Lines       65029    65031        +2     
  Branches    10174    10175        +1     
===========================================
+ Hits        46461    53991     +7530     
+ Misses      16105     8419     -7686     
- Partials     2463     2621      +158     
Flag Coverage Δ
keras 82.84% <0.00%> (+11.52%) ⬆️
keras-jax 61.44% <0.00%> (-0.01%) ⬇️
keras-numpy 55.63% <0.00%> (+<0.01%) ⬆️
keras-openvino 38.72% <0.00%> (?)
keras-tensorflow 62.70% <0.00%> (?)
keras-torch 61.54% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plot_model rankdir="LR" does not show U-shape plot for a UNet

3 participants