Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes to caching #9438

Merged
merged 9 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions gradio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,23 @@ def __init__(
)

if cache_examples is None:
if cache_examples_env := os.getenv("GRADIO_CACHE_EXAMPLES"):
if cache_examples_env.lower() == "true":
if fn is not None and outputs is not None:
self.cache_examples = True
else:
self.cache_examples = False
elif utils.get_space() and fn is not None and outputs is not None:
self.cache_examples = True
Copy link
Member Author

Choose a reason for hiding this comment

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

I also got rid of this logic and instead set the GRADIO_CACHE_EXAMPLES env in the Spaces Dockerfile: https://github.com/huggingface-internal/workloads/pull/2379

else:
self.cache_examples = cache_examples or False
else:
if cache_examples not in [True, False]:
raise ValueError(
"The `cache_examples` parameter must either: True or False."
)
if os.getenv("GRADIO_CACHE_EXAMPLES", "").lower() == "true":
if fn is not None and outputs is not None:
self.cache_examples = True
else:
self.cache_examples = False
elif cache_examples == "lazy":
warnings.warn(
"The `cache_examples` parameter no longer accepts a value of 'lazy'. To enable lazy caching in "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not enable lazy caching in this case instead of not caching at all since we're soft deprecating?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's fair actually, I'll make the change

"Gradio, you should set `cache_examples=True`, and `cache_mode='lazy'. Defaulting to cache_examples=False"
)
self.cache_examples = False
elif cache_examples in [True, False]:
self.cache_examples = cache_examples

else:
raise ValueError(
f"The `cache_exaples` parameter should be either True or False, not {cache_examples}"
)
if self.cache_examples and (fn is None or outputs is None):
raise ValueError("If caching examples, `fn` and `outputs` must be provided")

Expand Down
Loading