Loading model weights via timm from huggingface not possible. `_pickle.UnpicklingError: invalid load key, '<'.`

I want to load this model:

import timm
model = timm.create_model("hf_hub:edadaltocg/resnet18_cifar100", num_classes=100, pretrained=True)

Error

RuntimeError: Error(s) in loading state_dict for ResNet:
        size mismatch for conv1.weight: copying a param with shape torch.Size([64, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([64, 3, 7, 7]).

Then, I changed the code to:

        model = timm.create_model("hf_hub:edadaltocg/resnet18_cifar100", num_classes=100, pretrained=False)
        # override model
        model.conv1 = nn.Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        model.maxpool = nn.Identity()

        model.load_state_dict(
        torch.hub.load_state_dict_from_url(
            "https://huggingface.co/edadaltocg/resnet18_cifar100/resolve/main/pytorch_model.bin",
            map_location="cpu", 
            file_name="resnet18_cifar100.pth",
            )
        )

Is this correct? It tells me then

torch/serialization.py", line 1246, in _legacy_load
    magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '<'.

My package versions:

timm                      0.9.12
torch                     2.1.1
torcheval                 0.0.7

Solved.

I just removed file_name="resnet18_cifar100.pth",.