Skip to content

Commit

Permalink
FIX: Hack to include hparams of img tokenizer model when a `ListConfi…
Browse files Browse the repository at this point in the history
…g` is used for the `_args_` positional args
  • Loading branch information
nathanpainchaud committed Nov 6, 2023
1 parent da0f8d9 commit c2af6ef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions didactic/tasks/cardiac_multimodal_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def __init__(

super().__init__(*args, **kwargs)

# TOFIX: Hack to log image tokenizer model's hparams when it's a config for a `torch.nn.Sequential` object
# In that case, we have to use a `ListConfig` for the reserved `_args_` key. However, the automatic
# serialization of `_args_` fails (w/ a '`DictConfig' not JSON serializable' error). Therefore, we fix it by
# manually unpacking and logging the first and only element in the `_args_` `ListConfig`
if isinstance(img_tokenizer, DictConfig):
if img_tokenizer.get("model", {}).get("_target_") == "torch.nn.Sequential":
self.save_hyperparameters({"img_tokenizer/model/_args_/0": img_tokenizer.model._args_[0]})

# Add shortcut to lr to work with Lightning's learning rate finder
self.hparams.lr = None

Expand Down

0 comments on commit c2af6ef

Please sign in to comment.