chaiNNer-org / spandrel

Spandrel gives your project support for various PyTorch architectures meant for AI Super-Resolution, restoration, and inpainting. Based on the model support implemented in chaiNNer.
MIT License
105 stars 7 forks source link

Add internal hyperparameter API #164

Closed RunDevelopment closed 4 months ago

RunDevelopment commented 4 months ago

This PR adds an internal API for hyperparameters. The basic idea is that the model classes now have a @store_hyperparameters decorator that changes the class to automatically store all given hyperparameters in a hyperparameters field. Example:

@store_hyperparameters()
class CodeFormer(VQAutoEncoder):
    hyperparameters = {}

Unfortunately, classes still have to declare the hyperparameters class variable for pyright to pick up on the field.

While all models now have a hyperparameters field, this field is not part of the public API (for now). In this PR, I just add implementation for hyperparameters and use them in tests.

Speaking of tests: assert_loads_correctly now uses the new hyperparameters to test whether a model was loaded correctly. This is much stricter than the old opt-in system via condition=... and already found a few minor differences between detected hyperparameters.

A future PR will deal with defining the public API for hyperparameters.