gramineproject / examples

Sample applications configs for Gramine
BSD 3-Clause "New" or "Revised" License
28 stars 22 forks source link

Pytorch model download failing with 'no attribute error' #53

Closed nakuldes closed 1 year ago

nakuldes commented 1 year ago

With recent commit https://github.com/gramineproject/examples/commit/2e41bcd1d1887a364fced4bd220e654c9ae41ff0 We're not able to download model for pytorch. It fails with below error

python3 download-pretrained-model.py

Traceback (most recent call last):
  File "download-pretrained-model.py", line 5, in <module>
    alexnet = models.alexnet(weights=models.AlexNet_Weights.IMAGENET1K_V1)
AttributeError: module 'torchvision.models' has no attribute 'AlexNet_Weights'

On reverting the changes back, the model is getting successfully downloaded. python3 download-pretrained-model.py

Downloading: "https://download.pytorch.org/models/alexnet-owt-7be5be79.pth" to /tmp/.cache/torch/hub/checkpoints/alexnet-owt-7be5be79.pth
100.0%
Pre-trained model was saved in "alexnet-pretrained.pt"
dimakuv commented 1 year ago

The context for this commit can be found here: https://github.com/gramineproject/examples/pull/52

Looks like you're using an old version of PyTorch/TorchVision?

anjalirai-intel commented 1 year ago

We are using the default version comes with 18.04 and centos as well as RHEL. It passes for Ubuntu 20.04 & Ubuntu 22.04 but fails for all other configurations

dimakuv commented 1 year ago

So what do we do? Revert that change? What would be a good way to fix this warning and preserve the behavior for older versions of PyTorch?

mkow commented 1 year ago

I wouldn't care, we're dropping 18.04 support now and also, these are only examples. If someone insists on using outdated software then they can just use that older commit which works on 18.04 ¯\_(ツ)_/¯

anjalirai-intel commented 1 year ago

@mkow

It is not they are using outdated software, and this issue is only limited to Ubuntu 18.04.

This issue is among Ubuntu 18.04, Centos 8 and RHEL as well, and they come with Python3.6 In order to upgrade torchvision, we also need to upgrade Python as well. the latest version of torchvision requires Python3.7 and above

mkow commented 1 year ago

It is not they are using outdated software

Ubuntu 18.04, Centos 8

...?

dimakuv commented 1 year ago

Looks like the really correct solution would be to check the version of torchvision (in that download-pretrained-model.py Python script), and based on the version (a) do the old stuff, (b) do the new stuff.

jkr0103 commented 1 year ago

This change will go in v1.5 version where we will not have support for Ubuntu 18.04, IMO, that should be fine. We see the same issue in Curated-Apps also that we can fix by using example repo v1.4

dimakuv commented 1 year ago

This change will go in v1.5 version where we will not have support for Ubuntu 18.04, IMO, that should be fine.

But the problem seems to be with CentOS 8 and RHEL 8. And RHEL 8 has end-of-life in 2031 (!) for example: https://access.redhat.com/product-life-cycles/?product=Red%20Hat%20Enterprise%20Linux,OpenShift%20Container%20Platform%204

So it looks like we do need to support the older version of PyTorch/TorchVision.

mkow commented 1 year ago

And RHEL 8 has end-of-life in 2031

This doesn't mean that we'll support RHEL for the next 9 years. We support only decently modern distros.

dimakuv commented 1 year ago

This doesn't mean that we'll support RHEL for the next 9 years. We support only decently modern distros.

Well, I don't know, the currently discussed snippet (the required change to support both old and new PyTorches) is ~5 lines of code. It's such a small matter, and it breaks PyTorch + Gramine for more than one folks, that we could support it.

Let me just submit a PR that does it.

dimakuv commented 1 year ago

Here is my trivial PR: https://github.com/gramineproject/examples/pull/56

@anjalirai-intel Could you test my PR?

@mkow @jkr0103 What do you think? Looks like a trivial change.

anjalirai-intel commented 1 year ago

@dimakuv I validated the PR and we were able to download successfully and run pytorch. Tested it across Ubuntu 18.04, Ubuntu 20.04, CentOS 8 & RHEL. It was successful.

jkr0103 commented 1 year ago

LGTM

mkow commented 1 year ago

Well, I don't know, the currently discussed snippet (the required change to support both old and new PyTorches) is ~5 lines of code. It's such a small matter, and it breaks PyTorch + Gramine for more than one folks, that we could support it.

If you want to spend time on this then ok, but 18.04 and similar will break in a moment anyways, because Gramine is dropping support for them.

dimakuv commented 1 year ago

...but 18.04 and similar will break in a moment anyways, because Gramine is dropping support for them.

Hm. I feel like we'll make many people unhappy about it (and I'm mainly thinking RHEL 8 now). On the other hand, this will be about Gramine dependencies, and there should be workarounds in those old distros. So we'll make life harder for people who use RHEL 8, but I guess they'll still be able to use newer Gramine versions (albeit with some tricks).