dingo-gw / dingo

Dingo: Deep inference for gravitational-wave observations
MIT License
51 stars 16 forks source link

Load model in meta state #250

Closed annalena-k closed 4 weeks ago

annalena-k commented 1 month ago

This PR addresses the problem of loading the full DINGO model just to get access to its metadata. PyTorch provides the option of loading a model to the "meta" device which allows users to load a representation of the model without loading the actual parameters into memory. As a result, we can access the metadata of the model with lower memory requirements than before.

The model is loaded to map_location="meta"

Loading the model to map_location="meta" requires changes to dingo/core/models/posterior_model.py since operations like model.to(device) and model.load_state_dict(d["model_state_dict"]) cannot be performed for a model on "meta" devices.

This PR was tested on the NPE tutorial example and runs without problems.