Repository navigation
fix(cache): make task fingerprints deterministic and collision-free #1207
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
Open
AxelNoun
wants to merge
12
commits into
sunlabuiuc:master
Choose a base branch
from
AxelNoun:fix/task-fingerprint-916
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,354
−127
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4f7f012
fix(cache): make task fingerprints deterministic and collision-free
AxelNoun 6b90a2f
Merge remote-tracking branch 'upstream/master' into fix/task-fingerpr…
AxelNoun f09da8a
Fusionner upstream/master (4a173f7) dans fix/task-fingerprint-916
AxelNoun 9c715d1
Fusionner upstream/master (0e691f8) dans fix/task-fingerprint-916
AxelNoun d47b0ce
fix(cache): keep recorded init args out of vars(task)
AxelNoun 734c1eb
fix(cache): fingerprint effective task state, not raw init args
AxelNoun ebe269e
fix(cache): fingerprint captured state and table labels
AxelNoun ad2c214
fix(cache): locate lambdas in their file and keep numpy scalar dtypes
AxelNoun c0234ba
fix(cache): walk the task once per sidecar and drop the old EHR key s…
AxelNoun 8ead696
test(cache): fingerprint every shipped task under the strict default
AxelNoun 4088040
test(cache): skip shipped tasks that cannot be built from their defaults
AxelNoun c10fc3d
fix(cache): canonicalise the task name and version in the spec
AxelNoun 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| pyhealth.tasks.fingerprint | ||
| ======================================= | ||
|
|
||
| Deterministic cache keys for ``set_task``. Replaces the previous | ||
| ``json.dumps(..., default=str)`` hash, which was neither stable across | ||
| processes nor injective for large arrays. | ||
|
|
||
| .. automodule:: pyhealth.tasks.fingerprint | ||
| :members: UnfingerprintableError, task_spec, task_fingerprint, task_cache_name, processors_fingerprint, write_task_metadata, slugify | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| :exclude-members: Any, Mapping, Path, PurePath |
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """Show that task cache keys include the task's effective configuration (#916). | ||
|
|
||
| Two ReadmissionPredictionMIMIC3 configurations that differ only by | ||
| ``window`` must produce different cache directory names. A slash in | ||
| ``task_name`` (as used by BenchmarkEHRShot) is slugified to a single | ||
| path component. | ||
| """ | ||
|
|
||
| from datetime import timedelta | ||
|
|
||
| from pyhealth.tasks.benchmark_ehrshot import BenchmarkEHRShot | ||
| from pyhealth.tasks.fingerprint import task_cache_name, task_fingerprint | ||
| from pyhealth.tasks.readmission_prediction import ReadmissionPredictionMIMIC3 | ||
|
|
||
| if __name__ == "__main__": | ||
| t15 = ReadmissionPredictionMIMIC3() | ||
| t30 = ReadmissionPredictionMIMIC3(window=timedelta(days=30)) | ||
| print("15-day window:", task_cache_name(t15)) | ||
| print("30-day window:", task_cache_name(t30)) | ||
| assert task_fingerprint(t15) != task_fingerprint(t30) | ||
|
|
||
| ehrshot = task_cache_name(BenchmarkEHRShot(task="guo_los")) | ||
| print("EHRShot guo_los:", ehrshot) | ||
| assert "/" not in ehrshot |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Done in c0234ba. The page now says that functions stored on a task are the exception: their code is part of the hash, so editing one, in user code or in PyHealth, gives a new cache.