Skip to content

Conversation

davidberenstein1957
Copy link

@davidberenstein1957 davidberenstein1957 commented Aug 12, 2025

This update enhances support for Pruna AI, providing users with tailored code snippets for model integrations with Transformers and Diffusers.

  • Introduced a new library entry for Pruna AI in model-libraries.
  • Added main entry point and specific snippet generation functions for diffusers and transformers models.
  • Cleaned up whitespace inconsistencies in existing snippets.

TLDR: Pruna API normally mimics the Transformers and Diffusers API, so we can use PrunaModel.from_pretrained on top of pipelines or specific models. We re-use the underlying snippets for both the library and do some greedy replacements of certain part of the code snippets.

example

import torch
from diffusers import FluxFillPipeline
from diffusers.utils import load_image

image = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup.png")
mask = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup_mask.png")

pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
image = pipe(
    prompt="a white paper cup",
    image=image,
    mask_image=mask,
    height=1632,
    width=1232,
    guidance_scale=30,
    num_inference_steps=50,
    max_sequence_length=512,
    generator=torch.Generator("cpu").manual_seed(0)
).images[0]
image.save(f"flux-fill-dev.png")

becomes

import torch
from pruna import PrunaModel
from diffusers.utils import load_image

image = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup.png")
mask = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup_mask.png")

pipe = PrunaModel.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
image = pipe(
    prompt="a white paper cup",
    image=image,
    mask_image=mask,
    height=1632,
    width=1232,
    guidance_scale=30,
    num_inference_steps=50,
    max_sequence_length=512,
    generator=torch.Generator("cpu").manual_seed(0)
).images[0]
image.save(f"flux-fill-dev.png")

- Introduced a new library entry for Pruna AI in model-libraries.
- Added main entry point and specific snippet generation functions for diffusers and transformers models.
- Cleaned up whitespace inconsistencies in existing snippets.

This update enhances support for Pruna AI, providing users with tailored code snippets for model integration.
@sharpenb
Copy link

This is super cool :) It looks good from the Pruna side. Loading models with this snippet would facilitate their compression to make them more efficient.

Copy link
Contributor

@merveenoyan merveenoyan left a comment

Choose a reason for hiding this comment

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

thanks a lot, it's nice to see you here! interestingly this adds a lot of newlines, would be great to run linter

I think no need for a lot of comments to keep the code minimal :)

Copy link
Member

@Vaibhavs10 Vaibhavs10 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @davidberenstein1957 - let's wait for @Wauplin to give it a review, since this PR is a bit more involved!

- Added a new function `pruna_pro` for generating tailored code snippets for Pruna AI models.
- Updated the model libraries to include Pruna AI with appropriate repository details and snippet references.
- Improved code readability by standardizing function syntax and cleaning up whitespace.

This update further supports the integration of Pruna AI, providing users with enhanced code generation capabilities.
- Introduced a new entry for PXIA in the model-libraries, including repository details and snippet references.
- Enhanced the library structure to support additional model integrations.

This update expands the capabilities of the model-libraries, providing users with access to PXIA resources.
@davidberenstein1957
Copy link
Author

@Vaibhavs10 @merveenoyan, thanks for the review. :) I've resolved the formatting. I realised that the formatting commands in the Readme were merely checking and not applying the formatting directly. @Wauplin, feel free to give it a go. I can remove all comments if needed, but given that it is a bit more involved, I think they help with clarity around the formatting steps. Let me know what you prefer :)

Comment on lines 794 to 800
"pruna_pro-ai": {
prettyLabel: "Pruna AI",
repoName: "Pruna AI",
repoUrl: "https://github.com/Pruna-AI/pruna-ai",
snippets: snippets.pruna_pro,
docsUrl: "https://docs.pruna.ai",
},
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit weird to me that two different "libraries" would show up with the same name. In addition, there are only two test models on the Hub that use library pruna_pro-ai.

return pruna_default(model);
};

export const pruna_diffusers = (model: ModelData): string[] => {
Copy link
Member

Choose a reason for hiding this comment

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

Will the snippets always be forward-compatible with new pipelines? As an alternative, we could provide some specific snippets here instead of doing replacements.


Copy link
Member

Choose a reason for hiding this comment

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

Personally, not a fan of unrelated formatting changes, but I'll let @Wauplin or @hanouticelina comment on best practices in this regard.

Choose a reason for hiding this comment

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

Thanks for the review. Happy to revert these changes if you feel it is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Best would be to revert these changes from this PR and open a new one with only the formatting changes 🙏 Would make the discussion cleaner to follow :)

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
@davidberenstein1957
Copy link
Author

@Wauplin @hanouticelina , ping :)

Comment on lines +794 to +800
"pruna_pro-ai": {
prettyLabel: "Pruna AI (pro)",
repoName: "Pruna AI (pro)",
repoUrl: "https://github.com/Pruna-AI/pruna-ai",
snippets: snippets.pruna_pro,
docsUrl: "https://docs.pruna.ai",
},
Copy link
Member

Choose a reason for hiding this comment

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

not a fan of having two ≠ libraries. IMO this should always be Pruna (and you can prompt users to upgrade to a "pro" version from inside your library/error-messages/documentation/etc)

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. Since https://github.com/PrunaAI/pruna is a single library, it should be linked to a single tag and then handle the "pro" models separately.

Note that in the pruna snippet above you receive ModelData as input:

export const pruna = (model: ModelData): string[] => {

this means you can return a different snippet based on model name or tags. For instance, you could choose that all "pro" pruna models have a name ending by -pro and return a different snippet in that case.

"pruna-ai": {
prettyLabel: "Pruna AI",
repoName: "Pruna AI",
repoUrl: "https://github.com/Pruna-AI/pruna-ai",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm getting a 404 on this link. Shouldn't it be https://github.com/PrunaAI/pruna instead?

Suggested change
repoUrl: "https://github.com/Pruna-AI/pruna-ai",
repoUrl: "https://github.com/PrunaAI/pruna",

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.

7 participants