Skip to content

feat: 277 feature update modelcard to include a snippet and base model#282

Merged
davidberenstein1957 merged 16 commits intomainfrom
feat/277-feature-update-modelcard-to-include-a-snippet-and-base-model
Aug 8, 2025
Merged

feat: 277 feature update modelcard to include a snippet and base model#282
davidberenstein1957 merged 16 commits intomainfrom
feat/277-feature-update-modelcard-to-include-a-snippet-and-base-model

Conversation

@davidberenstein1957
Copy link
Copy Markdown
Member

@davidberenstein1957 davidberenstein1957 commented Jul 27, 2025

Description

Added multiple updates for better HF/transformers compatibility.

  • Renames hub methods to work better, HF-aligned naming
    • we can now push_to_hub instead of save_to_hub
    • we can now from_pretrained instead of from_hub
  • We updated the ModelCard to copy base model card info from the original loaded model and added nuance on running inference.

RENAMING

from transformers import AutoModelForCausalLM
from pruna.config.smash_config import SmashConfig
from pruna.engine.pruna_model import PrunaModel
from pruna import smash

download_repo_id = "hf-internal-testing/tiny-random-llama4"
upload_repo_id = "PrunaAI/test-save-tiny-random-llama4-smashed"
model = AutoModelForCausalLM.from_pretrained(download_repo_id)
smash_config = SmashConfig(device="cpu")
pruna_model = smash(
    model=model,
    smash_config=smash_config,
)
# we can now push_to_hub instead of save_to_hub
pruna_model.push_to_hub(upload_repo_id)
# we can now use from_pretrained instead of from_hub
pruna_model = PrunaModel.from_pretrained(upload_repo_id)

UPDATED MODEL CARD
Screenshot 2025-07-27 at 19 00 51

Related Issue

Fixes #277
Fixes #278

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?

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

Additional Notes

Copy link
Copy Markdown
Member

@sharpenb sharpenb left a comment

Choose a reason for hiding this comment

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

Faire renaming of functions. I left some comments. We should make sure that it does not increase maintenant needs.

Copy link
Copy Markdown
Member

@johannaSommer johannaSommer 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 addressing my comments David, LGTM!

@davidberenstein1957 davidberenstein1957 requested review from SaboniAmine and sharpenb and removed request for sharpenb August 8, 2025 08:39
@davidberenstein1957 davidberenstein1957 force-pushed the feat/277-feature-update-modelcard-to-include-a-snippet-and-base-model branch from 552b9b2 to 7e00587 Compare August 8, 2025 09:22
Copy link
Copy Markdown
Member

@sharpenb sharpenb 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 answers to my comment. I reopen the unaddressed comments and gave some more concrete suggestions to help solving them :)

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

- Updated `get_diffusers_unet_models` to use dynamic import for better module handling.
- Added `push_to_hub` method in `PrunaModel` for streamlined model repository uploads.
- Enhanced `from_pretrained` method to support loading from both local paths and Hugging Face Hub, with deprecation warning for `model_path`.
- Improved README generation in `save_pruna_model_to_hub` by utilizing `ModelCard` for better metadata handling.
- Updated model card template for improved documentation and flexibility in model usage instructions.
- Changed the tags in the model card to include "safetensors" alongside the dynamically generated library tag for improved clarity and categorization.
- Updated test functions to accept a parameter for the model loading method, allowing for more flexible testing of `from_hub` and `from_pretrained`.
- Adjusted assertions to utilize the selected method dynamically, improving code maintainability and readability.
- Introduced a `token` parameter in `push_to_hub` and `save_pruna_model_to_hub` methods to facilitate authentication when pushing models to the Hugging Face Hub.
- Updated model card generation to include the token for loading existing model cards.
- Enhanced the model card template to reference the base repository ID for improved documentation clarity.
- Modified the test case in `test_load.py` to include the `from_pretrained` method for the non-existent model, ensuring consistency in testing model loading methods.
…l_to_hub`

- Updated the `save_pruna_model_to_hub` function to ensure `model_name_or_path` is validated before checking repository existence.
- Improved the model card template to conditionally display inference instructions based on the presence of `base_repo_id` and `library_name`, enhancing documentation clarity.
- Changed the documentation link in the model card template to point to the updated Pruna documentation site for improved accessibility and accuracy.
- Updated the `PrunaModel` and `save_pruna_model_to_hub` functions to replace the `token` parameter with `hf_token`, enhancing clarity regarding its purpose for Hugging Face authentication.
- Adjusted related documentation to reflect the parameter name change, ensuring consistency across the codebase.
- Renamed `save_to_hub` to `push_to_hub` in the `PrunaModel` class and related functions to standardize terminology across the codebase.
- Updated documentation and tutorial notebooks to reflect the new method names, ensuring clarity in model saving and loading processes.
- Adjusted test cases to utilize the updated method names, enhancing consistency in testing model interactions with the Hugging Face Hub.
…utorials

- Consolidated device selection logic in `image_generation.ipynb` and `llms.ipynb` to a single line for clarity.
- Streamlined the calculation of percentage differences in both notebooks, enhancing code readability.
- Ensured consistent formatting and structure across tutorial notebooks.
- Enhanced the formatting of code snippets in various tutorial notebooks for better readability, including consistent use of line breaks and indentation.
- Consolidated multiple lines into single lines where appropriate, particularly in model loading and configuration sections.
- Updated markdown cells to maintain clarity and consistency across tutorials, ensuring a smoother learning experience for users.
- Updated comments in the `save_pruna_model_to_hub` function to enhance clarity regarding the retrieval of the pruna library version, ensuring better understanding of the code's purpose and functionality.
- Bumped versions for `accelerate` (1.7.0 to 1.9.0), `aiohttp` (3.12.4 to 3.12.14), `yaspin` (3.1.0 to 2.2.0), and `zipp` (3.22.0 to 3.23.0).
- Adjusted dependency URLs and hashes for updated packages.
- Refined resolution markers for Python version compatibility.
…unctions

- Added a ValueError in the `PrunaModel` class to ensure a valid `pretrained_model_name_or_path` is provided, enhancing robustness.
- Updated the documentation in `save_load.rst` for clarity on loading the smashed model, correcting capitalization for consistency.
- Added new package `aenum` (version 3.1.16) and `kernels` (version 0.9.0) with their respective dependencies.
- Updated `hqq` version from 0.2.6 to 0.2.7.post1 and adjusted its source URL.
- Introduced `opencv-python` (version 4.11.0.86) with dependencies.
- Refined resolution markers for Python version compatibility across various packages, enhancing support for different platforms.
@davidberenstein1957 davidberenstein1957 force-pushed the feat/277-feature-update-modelcard-to-include-a-snippet-and-base-model branch from a88e4c4 to ece5a2d Compare August 8, 2025 13:33
Copy link
Copy Markdown
Member

@sharpenb sharpenb 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 incorporating all my comments! Let's go :)

@davidberenstein1957 davidberenstein1957 merged commit 2dc281b into main Aug 8, 2025
7 checks passed
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.

[FEATURE] align local and remote/hub saving methods [FEATURE] update ModelCard to include a snippet and base model

3 participants