Skip to content

⚡ Bolt: Optimize rebuild_padding with lazy platform resolution#6498

Open
ZeyuChen wants to merge 6 commits intodevelopfrom
bolt-optimize-rebuild-padding-15703239940177532441
Open

⚡ Bolt: Optimize rebuild_padding with lazy platform resolution#6498
ZeyuChen wants to merge 6 commits intodevelopfrom
bolt-optimize-rebuild-padding-15703239940177532441

Conversation

@ZeyuChen
Copy link
Member

Motivation

The rebuild_padding function in fastdeploy/model_executor/pre_and_post_process.py is called frequently during model execution. The original implementation checked current_platform.is_*() and performed local imports on every call, adding unnecessary overhead.

Modifications

  • Optimized rebuild_padding to resolve the platform-specific implementation once (lazy initialization) and cache it in a module-level global variable _rebuild_padding_impl.
  • Introduced wrapper functions for platforms (DCU, GCU, CPU) that require fewer arguments than the standard interface, unifying the call signature.

Usage or Command

No changes to usage or commands. The optimization is internal.

Accuracy Tests

  • Verified functionally using a mocked unit test (tests/test_rebuild_padding_mock.py - deleted after verification) which confirmed that the platform check is performed only once per process lifetime.
  • The logic preserves all original branching and argument handling.

Checklist

  • I have read the CONTRIBUTING document.
  • I have checked the code style.
  • I have run the tests and they pass.

PR created automatically by Jules for task 15703239940177532441 started by @ZeyuChen

Co-authored-by: ZeyuChen <1371212+ZeyuChen@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: ZeyuChen <1371212+ZeyuChen@users.noreply.github.com>
Co-authored-by: ZeyuChen <1371212+ZeyuChen@users.noreply.github.com>
Co-authored-by: ZeyuChen <1371212+ZeyuChen@users.noreply.github.com>
Co-authored-by: ZeyuChen <1371212+ZeyuChen@users.noreply.github.com>
Co-authored-by: ZeyuChen <1371212+ZeyuChen@users.noreply.github.com>
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.

2 participants