-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add caching to local execution (#592)
* Add initial structure of local cache using joblib Signed-off-by: Eduardo Apolinario <[email protected]> * Add bogus unit tests Signed-off-by: Eduardo Apolinario <[email protected]> * Add clear-cache make target Signed-off-by: Eduardo Apolinario <[email protected]> * Run `make requirements` Signed-off-by: Eduardo Apolinario <[email protected]> * Remove a few TODO Signed-off-by: Eduardo Apolinario <[email protected]> * Linting Signed-off-by: Eduardo Apolinario <[email protected]> * More linting Signed-off-by: Eduardo Apolinario <[email protected]> * Define LocalCache and replace uses of it in base_task.py Signed-off-by: Eduardo Apolinario <[email protected]> * LocalCache type hints Signed-off-by: Eduardo Apolinario <[email protected]> * Comment use of LocalCache in base_task.py Signed-off-by: Eduardo Apolinario <[email protected]> * Remove use of Optional from declaration of _memory Signed-off-by: Eduardo Apolinario <[email protected]> * Move comment closer to invocation of 'dispatch_execute_func' Signed-off-by: Eduardo Apolinario <[email protected]> * Use global counter to validate cache hits Signed-off-by: Eduardo Apolinario <[email protected]> * Use ~/.flyte/local-cache as the default location Signed-off-by: Eduardo Apolinario <[email protected]> * Force initialization in LocalCache.clear() Signed-off-by: Eduardo Apolinario <[email protected]> * Add pyflyte local-cache command Signed-off-by: Eduardo Apolinario <[email protected]> * Remove clear-cache make target Signed-off-by: Eduardo Apolinario <[email protected]> * Linting. Signed-off-by: Eduardo Apolinario <[email protected]> * More linting Signed-off-by: Eduardo Apolinario <[email protected]> * Add more tests Signed-off-by: Eduardo Apolinario <[email protected]> * Add constant for cache verbosity Signed-off-by: Eduardo Apolinario <[email protected]> * Add task name to cache key definition Signed-off-by: Eduardo Apolinario <[email protected]> * Add tests containing complex inputs and outputs Signed-off-by: Eduardo Apolinario <[email protected]> * Linting Signed-off-by: Eduardo Apolinario <[email protected]> * Comment the test used to confirm the use of task names in cache keys Signed-off-by: Eduardo Apolinario <[email protected]> * More linting Signed-off-by: Eduardo Apolinario <[email protected]> * Fix linting Signed-off-by: Eduardo Apolinario <[email protected]> Co-authored-by: eduardo apolinario <[email protected]>
- Loading branch information
1 parent
a137472
commit 86d3368
Showing
10 changed files
with
356 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import click | ||
|
||
from flytekit.core.local_cache import LocalCache | ||
|
||
|
||
@click.group("local-cache") | ||
def local_cache(): | ||
""" | ||
Interact with the local cache. | ||
""" | ||
pass | ||
|
||
|
||
@click.command("clear") | ||
def clear_local_cache(): | ||
""" | ||
This command will remove all stored objects from local cache. | ||
""" | ||
LocalCache.clear() | ||
|
||
|
||
local_cache.add_command(clear_local_cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Callable, List, Optional | ||
|
||
from joblib import Memory | ||
|
||
# Location in the file system where serialized objects will be stored | ||
# TODO: read from config | ||
CACHE_LOCATION = "~/.flyte/local-cache" | ||
# TODO: read from config | ||
CACHE_VERBOSITY = 5 | ||
|
||
|
||
class LocalCache(object): | ||
_memory: Memory | ||
_initialized: bool = False | ||
|
||
@staticmethod | ||
def initialize(): | ||
LocalCache._memory = Memory(CACHE_LOCATION, verbose=CACHE_VERBOSITY) | ||
LocalCache._initialized = True | ||
|
||
@staticmethod | ||
def cache(func: Callable, ignore: Optional[List[str]] = None): | ||
if not LocalCache._initialized: | ||
LocalCache.initialize() | ||
return LocalCache._memory.cache(func, ignore=ignore) | ||
|
||
@staticmethod | ||
def clear(): | ||
if not LocalCache._initialized: | ||
LocalCache.initialize() | ||
LocalCache._memory.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.