-
Notifications
You must be signed in to change notification settings - Fork 1.3k
push/pull: properly collect run cache #3768
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -106,9 +106,11 @@ def restore(self, stage): | |
|
|
||
| @staticmethod | ||
| def _transfer(func, from_remote, to_remote): | ||
| ret = [] | ||
|
|
||
| runs = from_remote.path_info / "runs" | ||
| if not from_remote.exists(runs): | ||
| return | ||
| return [] | ||
|
|
||
| for src in from_remote.walk_files(runs): | ||
| rel = src.relative_to(from_remote.path_info) | ||
|
|
@@ -118,9 +120,36 @@ def _transfer(func, from_remote, to_remote): | |
| if to_remote.exists(key) and first(to_remote.walk_files(key)): | ||
| continue | ||
| func(src, dst) | ||
| ret.append((src.parent.name, src.name)) | ||
|
|
||
| return ret | ||
|
|
||
| def push(self, remote): | ||
| remote = self.repo.cloud.get_remote(remote) | ||
| return self._transfer(remote.upload, self.repo.cache.local, remote) | ||
|
|
||
| def pull(self, remote): | ||
| remote = self.repo.cloud.get_remote(remote) | ||
| return self._transfer(remote.download, remote, self.repo.cache.local) | ||
|
|
||
| def get_used_cache(self, used_run_cache, *args, **kwargs): | ||
| from dvc.cache import NamedCache | ||
| from dvc.stage import create_stage, PipelineStage | ||
|
|
||
| cache = NamedCache() | ||
|
|
||
| for key, value in used_run_cache: | ||
| entry = self._load_cache(key, value) | ||
| if not entry: | ||
| continue | ||
| stage = create_stage( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this is hacky. But run cache has a very good control over what it can contain (see _get_stage_hash above), so we can do such things without any problems for now. |
||
| PipelineStage, | ||
| repo=self.repo, | ||
| path="dvc.yaml", | ||
| cmd=entry["cmd"], | ||
| deps=[dep["path"] for dep in entry["deps"]], | ||
| outs=[out["path"] for out in entry["outs"]], | ||
| ) | ||
| StageLoader.fill_from_lock(stage, entry) | ||
| cache.update(stage.get_used_cache(*args, **kwargs)) | ||
| return cache | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shame NamedCache relies on checksums so heavily(or rather push/pull itself), otherwise we could've fed stage_cache to it directly. But for now, this works fine.