Closed Raghvender1205 closed 2 years ago
Hmm, you give it a timm model, correct? Might be a version issue. What timm version do you have?
And if you set "distill_token": False
on line 133 of tome/patch/timm.py
, does it work?
I'll check and revert back
I installed timm on the colab so timm 0.4.12
it was.
dist_token
shouldn't be undefined in timm 0.4.12, according to the source:
https://github.com/rwightman/pytorch-image-models/blob/7096b52a613eefb4f6d8107366611c8983478b19/timm/models/vision_transformer.py#L264
Though, if hard-coding that flag to False
works, I can just push a work-around that checks if the transformer has that attribute.
on changing the self._tome_info['distill_token'] = False, it seems to breaks as now I am getting this
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[<ipython-input-28-18d855f21157>](https://localhost:8080/#) in <module>
1 # Run image through ViT model
2 # Return class idx
----> 3 model(img_tensor).topk(5).indices[0].tolist()
2 frames
[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in __getattr__(self, name)
1206 return modules[name]
1207 raise AttributeError("'{}' object has no attribute '{}'".format(
-> 1208 type(self).__name__, name))
1209
1210 def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:
AttributeError: 'ToMeVisionTransformer' object has no attribute '_tome_info'
What I meant was replaced the dictionary here: https://github.com/facebookresearch/ToMe/blob/main/tome/patch/timm.py#L126-L134 with
model._tome_info = {
"r": model.r,
"size": None,
"source": None,
"trace_source": trace_source,
"prop_attn": prop_attn,
"class_token": model.cls_token is not None,
"distill_token": False,
}
You'll have to recreate and re-patch the model.
Oh Ok. I did replace but it seems to not work. I think there should be PR for this though.
I've created a PR for the candidate fix. See if you can reset your collab and pull this pr instead: #3
I can't test what this changes because every version of timm I can find has that dist token, so I'm not sure what's up with your environment.
I'll check
On this branch the example benchmark_timm.ipynb
is working
Great, I'll merge.
I was trying out the
timm_validation.ipynb
from the examples directory on my Colab. I load the ViT Base model and uploaded an image. But when i tried patching my model withToMe
it gives out an errorThis is the stacktrace