Issues with concrete ml : "UnpicklingError: invalid load key, ‘v’." and how can I read ".ekl" files?

How to fix this for cifarqat(https://github.com/zama-ai/concrete-ml/blob/main/use_case_examples/cifar/cifar_brevitas_finetuning/CifarQuantizationAwareTraining.ipynb)
checkpoint = torch.load(
f"{param_c100[‘dir’]}/{param_c100[‘pre_trained_path’]}“, map_location=device
)
UnpicklingError Traceback (most recent call last)
Cell In[15], line 1
----> 1 checkpoint = torch.load(
2 f”{param_c100[‘dir’]}/{param_c100[‘pre_trained_path’]}", map_location=device
3 )

File ~/anaconda3/envs/concreteml/lib/python3.9/site-packages/torch/serialization.py:795, in load(f, map_location, pickle_module, weights_only, **pickle_load_args)
793 except RuntimeError as e:
794 raise pickle.UnpicklingError(UNSAFE_MESSAGE + str(e)) from None
→ 795 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)

File ~/anaconda3/envs/concreteml/lib/python3.9/site-packages/torch/serialization.py:1002, in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
996 if not hasattr(f, ‘readinto’) and (3, 8, 0) <= sys.version_info < (3, 8, 2):
997 raise RuntimeError(
998 "torch.load does not work with file-like objects that do not implement readinto on Python 3.8.0 and 3.8.1. "
999 f"Received object of type "{type(f)}". Please update to Python 3.8.2 or newer to restore this "
1000 “functionality.”)
→ 1002 magic_number = pickle_module.load(f, **pickle_load_args)
1003 if magic_number != MAGIC_NUMBER:
1004 raise RuntimeError(“Invalid magic number; corrupt file?”)

UnpicklingError: invalid load key, ‘v’.

Hello @Laser_beam,
I believe you need to pull LFS files using git lfs pull !

1 Like

but I tried executing the same step in colab it worked there ,without need of pulling lfs files,in the local setup I will try with the above

Well, the error you get basically means that your pre-train file containing weights does not have the expected format. Usually, this comes from the fact that it has not been pulled from LFS. The fact that it worked with google colab could come from several possiblities :

  • if you first ran the FromImageNetToCifar, new weights will be computed and saved as pre-trained files in the cifar10 and cifar200 directories
  • if you clone the repo and have git LFS already installed, LFS files might have been pulled by default (which might be the case with colab)

In any case, I still advise you yo pull LFS files if possible and run your notebook again. If that does not work, then maybe your file is corrupted and then cloning the repo once again should solve it.

Let me know how it goes !

1 Like

It works now , Thankyou @RomanBredehoft :smiley:

1 Like

Roman I had a question and also open for others , like we had pkl(pickle files) files above so we unpickled it , but in client server setting we have this pks ,ksk ,pbs key which are packed as one ekl file ( evaluation key file)
How do you generate this one file from this and how do we read ekl files?

Hello @Laser_beam ,
I guess you are talking about the ClientServer.ipynb notebook right ? These files are generated and read by some of the OnDiskNetwork’s methods , a class that is defined in this very notebook.

Basically, these files contain the keys’ bytes retrieved from the client.evaluation_keys.serialize() method, which is executed in Concrete ML under FHEModelClient’s get_serialized_evaluation_keys method. To read the serialized bytes strings (once read from the file0, you can call fhe.Value.deserialize on them (with from concrete import fhe). This is notably done in FHEModelClient’s deserialize_decrypt method.

Be aware: these byte strings can be very long, I advise you to only print a part of it (using serialized_evaluation_keys[:100] for example) !

Small note : please open a topic each time you have a specific error or question, and with a non-generic title, it also helps other users if they encounter a similar problem :wink:

Any clue how are we serializing it internally( I dont think we are dumping the binary files through pickle in this case?)

I you want to know more about internal serialization, you can have a look at Concrete’s source code :

Also, here are the links to Concrete’s documentation and complete source code, where you might find some answers when looking at internal concepts like these !

1 Like