ConvolutedDog commented on issue #18573:
URL: https://github.com/apache/tvm/issues/18573#issuecomment-3635193573

   ```bash
   UserWarning: The given buffer is not writable, and PyTorch does not support 
non-writable tensors. This means you can write to the underlying (supposedly 
non-writable) buffer using the tensor. You may want to copy the buffer 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 /pytorch/torch/csrc/utils/tensor_new.cpp:1581.)
   ```
   
   Perhaps the problem lies here. It typically occurs when using 
`torch.export.load()` to load a model, because PyTorch internally uses 
`torch.frombuffer()` for data deserialization.
   
   Therefore, you can try the version without serializing the model:
   ```python
   import torch
   import torch.nn as nn
   from tvm.relax.frontend.torch import from_exported_program
   
   input_size = 28 * 28
   num_classes = 10
   
   
   class SimpleNet(nn.Module):
       def __init__(self):
           super(SimpleNet, self).__init__()
           self.fc1 = nn.Linear(input_size, 128)
           self.fc2 = nn.Linear(128, num_classes)
   
       def forward(self, x: torch.Tensor):
           x = x.view(x.size(0), -1)
           x = torch.relu(self.fc1(x))
           x = self.fc2(x)
           return x
   
   
   model = SimpleNet()
   example_args = (torch.randn(1, 1, 28, 28).to(torch.device("cpu")),)
   exported_program = torch.export.export(model, example_args)
   mod = from_exported_program(exported_program)
   mod.show()
   ```
   
   If this program runs without issues, it would indicate that the problem is 
specifically related to the deserialization process (i.e., loading from the 
`.pt2` file) rather than the export or TVM conversion steps themselves.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to