Repository navigation
feat(init): make models and haiku dependencies lazily imported (#160) - #188
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Resolves #160
Currently, importing
clrsunconditionally importsclrs.models,clrs._src.decoders,clrs._src.processors, andget_processor_factory, which immediately depend ondm-haikuandchex. Users who only want to utilize the CLRS benchmark algorithms, specs, samplers, or generate datasets (e.g. for Hugging Face or custom model architectures) are unable to importclrswithout installingdm-haiku.Changes
__getattr__(PEP 562) inclrs/__init__.py:models,decoders,processors, andget_processor_factoryare now lazily loaded when accessed.ImportErrorinstructing the user to installdm-haiku.CLRSDataset,create_dataset,build_sampler,algorithms,specs,clrs_text, etc.) are readily available without requiringdm-haiku.probing.py:tensorflowimport inclrs/_src/probing.pyis safely handled so probing utilities can be used without TensorFlow.clrs/_src/lazy_import_test.pyverifying that core components are available, lazy attributes exist indir(clrs), and invalid attributes properly raiseAttributeError.Verification
python -m unittest clrs._src.lazy_import_testin an isolated environment withoutdm-haiku: 3 tests passed.clrs.modelswithoutdm-haikuraises a clearImportError.