Closed ananyahjha93 closed 3 years ago
This is a known issue with AttrDict: https://stackoverflow.com/questions/13693888/accessing-dict-elements-with-leading-underscores-in-django-templates
Hi @ananyahjha93,
First of all, thank you for using VISSL :)
Regarding the issue, I am not sure I understand how you concluded that we should rename "self.model_config._MODEL_INIT_SEED" to "self.model_config.MODEL_INIT_SEED".
You can make your code pass by renaming the key "MODEL_INIT_SEED"
to "_MODEL_INIT_SEED"
in the AttrDict
dictionary. Indeed, the following code should work to create the model via API (it does at least work on my side):
from vissl.config.attr_dict import AttrDict
from vissl.models import build_model
# where
model_config = AttrDict({
'SINGLE_PASS_EVERY_CROP': False,
'INPUT_TYPE': 'rgb',
'MULTI_INPUT_HEAD_MAPPING': [],
'TRUNK': AttrDict({
'NAME': 'vision_transformer',
'VISION_TRANSFORMERS': AttrDict({
'IMAGE_SIZE': 224,
'PATCH_SIZE': 16,
'NUM_LAYERS': 12,
'NUM_HEADS': 6,
'HIDDEN_DIM': 384,
'MLP_DIM': 1532,
'CLASSIFIER': 'token',
'DROPOUT_RATE': 0,
'ATTENTION_DROPOUT_RATE': 0,
'QKV_BIAS': True,
'QK_SCALE': False,
'DROP_PATH_RATE': 0.1,
}),
}),
'HEAD': AttrDict({
'PARAMS': [[
"swav_head",
{
"use_weight_norm_prototypes": True,
"dims": [384, 2048, 2048, 256],
"use_bn": False,
"return_embeddings": False,
"activation_name": "GELU",
"num_clusters": [65536]
}
]],
}),
'FEATURE_EVAL_SETTINGS': AttrDict({
'EVAL_MODE_ON': False,
'EXTRACT_TRUNK_FEATURES_ONLY': False,
}),
'_MODEL_INIT_SEED': 0,
})
optimizer_config = AttrDict({})
model = build_model(model_config, optimizer_config)
If it does not work on your side, please tell me, then this is definitely a bug.
As a side note, the reason why we have an underscore in front of "_MODEL_INIT_SEED" is because this attribute is deduced inside hydra_config.py
and thus private to the VISSL configuration (but clearly not private for the build_model
API, we can work on making that more clear).
@QuentinDuval sorry for the confusion, I was using _MODEL_INIT_SEED
in my config. Its weird that this works for you. OK like even if I do this, it fails for me
>>> from attrdict.dictionary import AttrDict
>>> a = AttrDict({'_PARAM': 1})
>>> a._PARAM
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/attrdict/mixins.py", line 80, in __getattr__
raise AttributeError(
AttributeError: 'AttrDict' instance has no attribute '_PARAM'
>>> a
AttrDict({'_PARAM': 1})
so I assumed that AttrDict is not compatible with keys starting with underscores.
Hi @ananyahjha93 !
Ok, so the issue is probably due to the import:
from vissl.config.attr_dict import AttrDict
a = AttrDict({'_PARAM': 1})
a._PARAM
We have our own AttrDict
class :)
Could you try that this works fine?
@QuentinDuval thanks, that makes sense, I went through the code of the original AttrDict and found that they do not support keys starting with an underscore because of a regex. Thanks for helping out!
Instructions To Reproduce the π Bug:
Expected behavior:
This API call should work with the config. Solution: Change calls of
to
within BaseSSLMultiInputOutputModel and other places where this is referenced.
Environment:
Provide your environment information using the following command:
When to expect Triage
VISSL devs and contributors aim to triage issues asap however, as a general guideline, we ask users to expect triaging in 1-2 weeks.