Skip to content

[export] Add export-safe LRU cache helper#13290

Open
cbensimon wants to merge 1 commit intomainfrom
export-safe-lru-cache
Open

[export] Add export-safe LRU cache helper#13290
cbensimon wants to merge 1 commit intomainfrom
export-safe-lru-cache

Conversation

@cbensimon
Copy link
Contributor

No description provided.

@cbensimon cbensimon requested a review from sayakpaul March 19, 2026 17:36
@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.


@functools.wraps(fn)
def inner_wrapper(*args: P.args, **kwargs: P.kwargs):
if torch.compiler.is_exporting():
Copy link
Member

Choose a reason for hiding this comment

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

Should we check if is_exporting exists with hastattr?

@functools.wraps(functools.lru_cache)
def lru_cache_unless_export(maxsize=128, typed=False):
def outer_wrapper(fn: Callable[P, T]):
cached = functools.lru_cache(maxsize=maxsize, typed=typed)(fn)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to specify typed?

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.

3 participants