-
Notifications
You must be signed in to change notification settings - Fork 244
Support for serialising detectors with keops backends #681
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
Show all changes
9 commits
Select commit
Hold shift + click to select a range
13c42fe
keops save/load support
2e7daea
Add missing saving/_keops submodule
c8e8ca5
Only test keops save/load when installed (on linux)
0930844
avoid keops imports when keops not installed
1b1b92a
Set sigma as float32
dbe24a9
Update changelog
5bb7314
Add comments re has_keops
669a8c6
Replace .copy()'s with deepcopy
35e3025
Type str as Literal in keops/kernels.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from alibi_detect.utils.missing_optional_dependency import import_optional | ||
|
|
||
| load_kernel_config_ke = import_optional( | ||
| 'alibi_detect.saving._keops.loading', | ||
| names=['load_kernel_config']) | ||
|
|
||
| __all__ = [ | ||
| "load_kernel_config_ke", | ||
| ] |
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,37 @@ | ||
| from typing import Callable | ||
| from alibi_detect.utils.keops.kernels import DeepKernel | ||
|
|
||
|
|
||
| def load_kernel_config(cfg: dict) -> Callable: | ||
| """ | ||
| Loads a kernel from a kernel config dict. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| cfg | ||
| A kernel config dict. (see pydantic schema's). | ||
|
|
||
| Returns | ||
| ------- | ||
| The kernel. | ||
| """ | ||
| if 'src' in cfg: # Standard kernel config | ||
| kernel = cfg.pop('src') | ||
| if hasattr(kernel, 'from_config'): | ||
| kernel = kernel.from_config(cfg) | ||
|
|
||
| elif 'proj' in cfg: # DeepKernel config | ||
| # Kernel a | ||
| kernel_a = cfg['kernel_a'] | ||
| kernel_b = cfg['kernel_b'] | ||
| if kernel_a != 'rbf': | ||
| cfg['kernel_a'] = load_kernel_config(kernel_a) | ||
| if kernel_b != 'rbf': | ||
| cfg['kernel_b'] = load_kernel_config(kernel_b) | ||
| # Assemble deep kernel | ||
| kernel = DeepKernel.from_config(cfg) | ||
|
|
||
| else: | ||
| raise ValueError('Unable to process kernel. The kernel config dict must either be a `KernelConfig` with a ' | ||
| '`src` field, or a `DeepkernelConfig` with a `proj` field.)') | ||
| return kernel |
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
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.
Uh oh!
There was an error while loading. Please reload this page.