Skip to content

Minor Refactoring of CodecManager#27

Merged
LTMeyer merged 10 commits intomainfrom
refactor
May 27, 2025
Merged

Minor Refactoring of CodecManager#27
LTMeyer merged 10 commits intomainfrom
refactor

Conversation

@LTMeyer
Copy link
Collaborator

@LTMeyer LTMeyer commented May 26, 2025

This PR refactors several small bits of the CodecManager.

  • Remove pydantic dependency by the use of dataclass. (pydantic is great if we actually perform some type checks, and this comes with more complex configuraiton). Standard libary dataclass is perfectly suited for our use case.
  • It improves typing by introducing CodecHFConfig, CodecType, ModalityTypeError, and TokenKeyError
  • Use lru_cache to cache both access to HF models (note that they are cached by default in the HF library), and codec retrieval from modality
  • Move codec to device only in the encode/decode method. Otherwise GPU memory could be saturated if too many codecs were loaded.

@LTMeyer LTMeyer requested a review from EiffL May 26, 2025 22:45
@EiffL
Copy link
Contributor

EiffL commented May 27, 2025

hummm, but would the following work in this approach:

from aion.modalities import LegacySurveyImage

print(LegacySurveyImage.name)

i.e. accessing class variables, without instantiating the class?

@LTMeyer
Copy link
Collaborator Author

LTMeyer commented May 27, 2025

hummm, but would the following work in this approach:

from aion.modalities import LegacySurveyImage

print(LegacySurveyImage.name)

i.e. accessing class variables, without instantiating the class?

Hmm. Just for me to understand. We only instantiate modalities when returned and when we populate the values field, otherwise we use the object type right?

@LTMeyer
Copy link
Collaborator Author

LTMeyer commented May 27, 2025

i.e. accessing class variables, without instantiating the class?

Sure we can (see https://docs.python.org/3/library/typing.html#typing.ClassVar). What is the need again?

@LTMeyer LTMeyer merged commit c8099c6 into main May 27, 2025
3 checks passed
@LTMeyer LTMeyer deleted the refactor branch May 27, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants