Loading saved models on host with different byteorder

Hi all,

I am attempting to load a pre-trained model (LE) on a big endian platform. The model is GitHub - ultralytics/yolov5: YOLOv5 馃殌 in PyTorch > ONNX > CoreML > TFLite

I am seeing that pytorch tensor objects are not converted to the appropriate byteorder. I opened an issue using a simpler model here: Saved model parameters are not portable to systems with different host byteorder 路 Issue #65300 路 pytorch/pytorch 路 GitHub

In the interim, I am trying to write a python tool to load and convert the tensors. I am hoping the community can provide a bit of guidance on how to (somewhat generically) loop through and find all of the tensor objects and bytes wap them.

So far, I would plan to loop and convert:

  • state_dict
  • optimizer_dict (I need to investigate this more to see if needed).

Are there other parameters we should watch for (generically)?
The quick example I have is the yolo model - in addition to the state_dict, there is a model level stride parameter (also tensor object) that needs to be adjust.

Has anyone experience anything similar? Any thought appreciated.
If there are similar model navigation tools (whether for optimization or other) that you are aware of, that would be great info too.

Thank you for any info you can provide!

my understanding is that only on-disk format is wrong, so you should convert what you deserialize. perhaps use numpy鈥檚 facilities - Byte-swapping 鈥 NumPy v1.21 Manual

Thanks Alex, that鈥檚 what I am utilizing and am able to convert the constants. Now researching other potentially related issues!