Skip to content

Rename Kimi resize helper for NaViT patch-grid semantics - #4094

Open
aswanth-07 wants to merge 1 commit into
pytorch:mainfrom
aswanth-07:agent/fix-padded-patch-budget
Open

Rename Kimi resize helper for NaViT patch-grid semantics#4094
aswanth-07 wants to merge 1 commit into
pytorch:mainfrom
aswanth-07:agent/fix-padded-patch-budget

Conversation

@aswanth-07

@aswanth-07 aswanth-07 commented Aug 9, 2026

Copy link
Copy Markdown

Summary

  • rename resize_to_patch_budget to resize_to_navit_patch_grid
  • preserve Kimi's existing NaViT resize and padding geometry
  • describe max_patches as a pre-padding patch budget
  • update all model, numerical-test, and unit-test call sites
  • add a focused test showing that merge-grid padding can raise the final patch count above the pre-padding budget

Rationale

The helper follows Kimi's navit_resize_image behavior. It applies the total and per-side limits while calculating the resize scale, then pads the result to the merge grid. That padding can make the final raw-patch count exceed max_patches.

The previous helper name implied a strict final budget. The new name describes the operation without changing the image geometry used by Titan's Kimi path.

Related: #4093

Validation

  • rebased onto current main at f81fc0afe
  • py -3.13 -m pytest tests/unit_tests/test_mm_dataset_preprocessing.py -q with plugin autoload disabled: 10 passed
  • Torchtitan pre-commit hooks for the five changed files: whitespace, AST, merge-conflict, large-file, EOF, license, flake8, ufmt, pydoclint, and codespell checks passed
  • py -3.13 -m compileall -q for the renamed model and test call sites: passed
  • git diff --check: passed

The optional grain dependency is unavailable on this host, so test_qwen_multimodal_data.py is left to dependency-complete CI. Local Pyrefly still expects the configured ../pytorch source checkout, so CI provides type validation.

AI assistance disclosure

OpenAI Codex assisted with repository auditing, implementation, test execution, and drafting this pull request. The updated code has not yet received a human code review.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 9, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@aswanth-07
aswanth-07 force-pushed the agent/fix-padded-patch-budget branch from 59bdbe0 to 54c6359 Compare August 11, 2026 08:09
@aswanth-07
aswanth-07 marked this pull request as ready for review August 11, 2026 08:09
@aswanth-07
aswanth-07 force-pushed the agent/fix-padded-patch-budget branch from 23dfd23 to 61be741 Compare August 24, 2026 03:04
@shuhuayu

Copy link
Copy Markdown
Contributor

hi @aswanth-07, the current approach is implemented to match the kimi's navit_resize_image (https://huggingface.co/moonshotai/Kimi-K2.7-Code/blob/main/media_utils.py#L85-L133), which does not compress the number of patches as this pr did. In this case, i would suggest renaming resize_to_patch_budget to resize_to_navit_patch_grid, and describe max_patches as a “pre-padding patch budget” rather than a strict maximum number of patches. if we implement the new function as in this pr, it is faithful to the name but not used in titan yet. what do you think?

@aswanth-07
aswanth-07 force-pushed the agent/fix-padded-patch-budget branch from 61be741 to bc517cc Compare August 24, 2026 09:05
@aswanth-07 aswanth-07 changed the title Fix padded image patch budget Rename Kimi resize helper for NaViT patch-grid semantics Aug 24, 2026
@aswanth-07

Copy link
Copy Markdown
Author

Thanks, that makes sense. I checked the behavior against Kimi's navit_resize_image and updated the PR accordingly. The post-padding compression is gone, so Titan keeps the existing Kimi geometry.

I renamed the helper to resize_to_navit_patch_grid across all call sites, documented max_patches as a pre-padding budget, and added a focused test showing that padding may take the final grid above that budget. I also closed #4093 since the reported behavior is expected for this path.

@aswanth-07
aswanth-07 force-pushed the agent/fix-padded-patch-budget branch from bc517cc to 0ee89e9 Compare August 24, 2026 09:07
@shuhuayu

Copy link
Copy Markdown
Contributor

looks good to me, can you also refactor the kimi k3 model?

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

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants