iree-org / iree-turbine

IREE's PyTorch Frontend, based on Torch Dynamo.
Apache License 2.0
43 stars 24 forks source link

Warning about non-writable tensors from params.py #9

Open ScottTodd opened 5 months ago

ScottTodd commented 5 months ago

Observed while running the downstream https://github.com/nod-ai/sharktank/blob/main/sharktank/tests/types/dataset_test.py

sharktank/tests/types/dataset_test.py::DatasetTest::testDatasetRoundtrip
  D:\dev\projects\sharktank\deps\shark-turbine\shark_turbine\aot\params.py:163: UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This means writing to this tensor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:212.)
    return torch.from_numpy(wrapper)

The warning goes away if I flip copy=False to copy=True here: https://github.com/iree-org/iree-turbine/blob/352095854a5b3c78a6377fdc941251618cbc3bb6/shark_turbine/aot/params.py#L156-L159

I imagine we want to avoid copies of large files though, and behavior seems to be correct even with the undefined behavior. Is that warning relevant for our usage? https://github.com/pytorch/pytorch/blob/f1d1e3246f3203a4c9641fcda28b0ed66eb8f4d4/torch/csrc/utils/tensor_numpy.cpp#L205C6-L232

stellaraccident commented 5 months ago

It's fine. Ignore it.