Skip to content

fix(janus): Handle None values in image generation mode#44793

Closed
BillionClaw wants to merge 1 commit intohuggingface:mainfrom
BillionClaw:clawoss/fix-janus-image-generation-44792
Closed

fix(janus): Handle None values in image generation mode#44793
BillionClaw wants to merge 1 commit intohuggingface:mainfrom
BillionClaw:clawoss/fix-janus-image-generation-44792

Conversation

@BillionClaw
Copy link
Copy Markdown

What does this PR do?

Fixes #44792 - Handles None values in Janus model's image generation mode.

The generate() method for image generation had several places where it assumed certain config values would always be set, causing failures when they were None:

  1. generation_config.num_return_sequences could be None, causing errors in _expand_inputs_for_generation - now defaults to 1
  2. generation_config.generation_kwargs["boi_token_id"] was accessed without checking if generation_kwargs existed - now safely initialized
  3. generation_config.pad_token_id could be None - now falls back to config value
  4. max_cache_len calculation failed when max_length was None - now properly computes a safe minimum cache length with buffer

Before submitting

  • This PR fixes a bug
  • I have run the existing Janus tests and they all pass (193 passed)

Tagging: @zucchini-nlp for multimodal models

Fix several issues in JanusForConditionalGeneration.generate() when
generation_config has None values:

- Handle num_return_sequences=None by defaulting to 1
- Add safety checks for generation_kwargs and boi_token_id
- Handle pad_token_id=None by falling back to config value
- Fix max_cache_len calculation when max_length is None

Fixes huggingface#44792
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: janus

@BillionClaw
Copy link
Copy Markdown
Author

Hi! Just checking in on this PR. Is there anything needed from my side to help move it forward?

Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

omg, i didn't post comments and they were pending 🤦🏻

input_ids=input_ids,
attention_mask=attention_mask,
expand_size=generation_config.num_return_sequences,
expand_size=generation_config.num_return_sequences or 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we just need to call _prepare_generation_config in the very beginning, it is missing

attention_mask = attention_mask.repeat(2, 1)
model_kwargs["attention_mask"] = attention_mask

# Ensure generation_kwargs exists with boi_token_id
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

prob this and rest will be resolved after calling _prepare_generation_config

@onthebed
Copy link
Copy Markdown

Friendly bump on this PR — happy to make changes or close it out if it is no longer useful.

@zucchini-nlp
Copy link
Copy Markdown
Member

Fixed by #45044, closing

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.

Failed test case test_model_generate_images for janus model

3 participants