Skip to content

feat: add pruner algroithm#470

Merged
minettekaum merged 3 commits intomainfrom
feat/pruner-algorithm
Feb 23, 2026
Merged

feat: add pruner algroithm#470
minettekaum merged 3 commits intomainfrom
feat/pruner-algorithm

Conversation

@minettekaum
Copy link
Copy Markdown
Contributor

Description

I added padding_pruning algorithm and flux_tiny_random_with_tokenizer to fixtures to be able to test padded_pruning

  • You can find padding_pruning algorithm in src/pruna/algorithms/padding_pruning.py
  • You can find tests for padding_pruning algorithm in tests/algorithms/testers/padding_pruning.py
  • You can find flux_tiny_random_with_tokenizer added in tests/fixtures.py so that padding_pruning algorithm can be tested.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Yes, by tests for padding_pruning.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Comment @cursor review or bugbot run to trigger another review on this PR


prompts = self._extract_prompts(args, kwargs)
max_num_tokens = max(len(self.tokenizer.encode(p)) for p in prompts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Fails when prompts are not strings

wrapped_call computes max_num_tokens via max(... for p in prompts), but _extract_prompts can return an empty list (e.g., callers pass prompt_embeds/no prompt strings). This triggers a runtime ValueError and breaks inference for valid diffusers call patterns.

Fix in Cursor Fix in Web

sequence_length *= 2
if sequence_length >= max_sequence_length:
sequence_length = max_sequence_length
kwargs["max_sequence_length"] = sequence_length
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Assumes max_sequence_length has a default

default_max_sequence_length is read from inspect.signature(...).parameters["max_sequence_length"].default. If that default is inspect._empty (or the user passes max_sequence_length=None), comparisons like sequence_length >= max_sequence_length can raise TypeError, causing runtime failures on pipelines with a required max_sequence_length.

Fix in Cursor Fix in Web

"""Disable prompt pruning by unwrapping the pipe."""
if self.pipe_call:
self.pipe.__call__ = self.pipe_call

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Helper disable may crash before enable

disable accesses self.pipe_call without initializing it in __init__. If disable is called before enable/wrap_pipe runs (or after partial initialization failures), this can raise AttributeError and prevent cleanup/saving flows that call .disable() on helpers.

Fix in Cursor Fix in Web

@minettekaum minettekaum changed the title feat/pruner-algroithm: added padding_pruning algorithm feat: add pruner-algroithm Dec 19, 2025
@minettekaum minettekaum changed the title feat: add pruner-algroithm feat: add pruner algroithm Dec 19, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 3, 2026

This PR has been inactive for 10 days and is now marked as stale.

@github-actions github-actions bot added the stale label Jan 3, 2026
@github-actions github-actions bot closed this Jan 10, 2026
@minettekaum minettekaum reopened this Jan 14, 2026
@github-actions github-actions bot removed the stale label Jan 15, 2026
@minettekaum minettekaum requested a review from begumcig January 15, 2026 10:36
@github-actions
Copy link
Copy Markdown

This PR has been inactive for 10 days and is now marked as stale.

@github-actions github-actions bot added the stale label Jan 26, 2026
Copy link
Copy Markdown
Collaborator

@nifleisch nifleisch left a comment

Choose a reason for hiding this comment

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

Looks good to me 🙌

Comment thread src/pruna/algorithms/padding_pruning.py Outdated

class PaddingPruningHelper:
"""
Helper for Prompt Pruning.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Typo, I guess it should be "Helper for Padding Pruning."

@github-actions github-actions bot removed the stale label Jan 30, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 9, 2026

This PR has been inactive for 10 days and is now marked as stale.

Copy link
Copy Markdown
Member

@begumcig begumcig left a comment

Choose a reason for hiding this comment

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

Thank you so much Minette looks super good to me!

@github-actions github-actions bot removed the stale label Feb 11, 2026
@github-actions
Copy link
Copy Markdown

This PR has been inactive for 10 days and is now marked as stale.

@github-actions github-actions bot added the stale label Feb 22, 2026
Ubuntu and others added 3 commits February 23, 2026 10:22
Co-authored-by: Nils Fleischmann <nils.fleischmann@outlook.com>
@minettekaum minettekaum force-pushed the feat/pruner-algorithm branch from 18e5c1e to a42238e Compare February 23, 2026 10:23
@minettekaum minettekaum merged commit 223ff38 into main Feb 23, 2026
7 checks passed
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.

3 participants