Skip to content

Conversation

torotoki
Copy link
Contributor

@torotoki torotoki commented Aug 29, 2025

What does this PR do?

This PR updates the obsolete sample code of MambaCache that does not work.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@torotoki torotoki changed the title Bugfix with cache_positon in MambaCache Fix crash when using cache_position in MambaCache Aug 29, 2025
@torotoki torotoki changed the title Fix crash when using cache_position in MambaCache (WIP) Fix crash when using cache_position in MambaCache Aug 29, 2025
@torotoki torotoki force-pushed the bugfix-with-mamba-cache-position branch from 20e4166 to 5b1c9c1 Compare August 30, 2025 05:23
@torotoki torotoki changed the title (WIP) Fix crash when using cache_position in MambaCache Fix crash when executing the sample code of MambaCache Aug 30, 2025
@torotoki torotoki changed the title Fix crash when executing the sample code of MambaCache Fix crash when executing MambaCache sample code Aug 30, 2025
@Rocketknight1
Copy link
Member

cc @gante @zucchini-nlp since this is based on cache updates

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@gante gante 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 for opening the PR and fixing the docs 🤗

Added a few minor corrections to make them flawless

>>> cache_position = torch.arange(len(inputs["input_ids"][0]), device=model.device) # sequence length
>>> outputs = model(**inputs, cache_params=cache_params, cache_position=cache_position, use_cache=True)
>>> outputs.cache_params
FalconMambaCache()
Copy link
Member

Choose a reason for hiding this comment

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

(this is not the output, let's remove this line too)

>>> cache_position = torch.arange(len(inputs["input_ids"][0]), device=model.device) # sequence length
>>> outputs = model(**inputs, cache_params=cache_params, cache_position=cache_position, use_cache=True)
>>> outputs.cache_params
MambaCache()
Copy link
Member

Choose a reason for hiding this comment

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

(same comment here)

@torotoki torotoki force-pushed the bugfix-with-mamba-cache-position branch 2 times, most recently from 4ef40ff to 18df233 Compare September 9, 2025 10:08
@torotoki torotoki force-pushed the bugfix-with-mamba-cache-position branch from 18df233 to 8a979c1 Compare September 9, 2025 10:11
Copy link
Member

@gante gante 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 for iterating and helping us make the library better 🤗

Copy link
Contributor

github-actions bot commented Sep 9, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: falcon_mamba, mamba

@gante gante enabled auto-merge (squash) September 9, 2025 16:37
@gante gante merged commit d09fdf5 into huggingface:main Sep 9, 2025
14 checks passed
@torotoki
Copy link
Contributor Author

Thanks for following up!

vijayabhaskar-ev pushed a commit to vijayabhaskar-ev/transformers that referenced this pull request Oct 2, 2025
* Fix the sample code of MambaCache

* Update automatically generated code

* Fix FalconMambaCache documents

* minor doc fixes

---------

Co-authored-by: Joao Gante <joao@huggingface.co>
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.

4 participants