File from Tutorial nn.Module causing error

Hello all,

When I run the tutorial code>
https://pytorch.org/tutorials/beginner/nn_tutorial.html
the cell for “pickel.load” causes an error:
Bildschirmfoto 2024-08-11 um 16.44.44
After my mac loaded the file and uncompressed it automatically, I compressed it back in Terminal with gzip. Still causes the error.

How can I fix it?
Regards
Sven

The issue might be related to this one pointing to a file corruption error.

Hi ptrblck

No, I downloaded the model with 2 different browser (Safari, Firefox) and got the same error.
changed the code to os.open the uncompressed file and got the same error.
Downloaded the file with the python code from the tutorial and downloaded it manually, both create the same error.
Can the mnist.pkl.gz file be not compatible with current pytorch versions?
Any idea?

Regards
Sven

No, I doubt it as it’s working fine for me using torch==2.4.0 and a recent nightly binary:

from pathlib import Path
import requests

DATA_PATH = Path("data_lala")
PATH = DATA_PATH / "mnist"

PATH.mkdir(parents=True, exist_ok=True)

URL = "https://github.com/pytorch/tutorials/raw/main/_static/"
FILENAME = "mnist.pkl.gz"

if not (PATH / FILENAME).exists():
        content = requests.get(URL + FILENAME).content
        (PATH / FILENAME).open("wb").write(content)
        
import pickle
import gzip

with gzip.open((PATH / FILENAME).as_posix(), "rb") as f:
        ((x_train, y_train), (x_valid, y_valid), _) = pickle.load(f, encoding="latin-1")

print(x_train.shape)
# (50000, 784)

Thank you ptrblk,

On MAC with torch 2.3.0 it fails, but on Linux with torch 2.5.0 it works.
Looks like a version issue. Anyway thanks for your great help

Regards
Sven