You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "raindrops-0199 (via GitHub)" <gi...@apache.org> on 2026/07/01 07:31:38 UTC

[I] [Bug] [Relax] `InternalError: Divide by zero` when compiling a `reshape` that yields a 0-sized dimension [tvm]

raindrops-0199 opened a new issue, #19922:
URL: https://github.com/apache/tvm/issues/19922

   ### Expected behavior
   
   `tvm.compile` should compile a Relax module containing a `reshape` whose result has a
   0-sized dimension (e.g. reshaping an empty intermediate tensor to `(-1, 10)`, which yields
   shape `(0, 10)`). A 0-sized dimension is a legal empty-tensor shape: eager PyTorch,
   `torch.export`, and the `from_exported_program` frontend all accept this model, and eager
   returns a valid `(0, 10)` tensor.
   
   ### Actual behavior
   
   `tvm.compile` aborts at compile time with:
   ```
   tvm.error.InternalError: Check failed: pb->value != 0 (0 vs. 0) : Divide by zero
     File ".../src/tirx/op/op.cc", line 623, in tvm::floormod(tvm::PrimExpr, tvm::PrimExpr, tvm::Span)
       if (auto ret = arith::TryConstFold<tirx::FloorMod>(a, b)) return ret.value();
     File ".../src/arith/const_fold.h", line 322, in tvm::arith::TryConstFold(...) [Op = tvm::tirx::FloorMod]
       TVM_FFI_ICHECK_NE(pb->value, 0) << "Divide by zero";
   ```
   
   ### Environment
   
   - TVM: 0.25.dev0 (commit `6b4b866d6`)
   - PyTorch: 2.12.0+cu130
   - Python: 3.12
   - OS: Ubuntu x86_64
   - Target: `llvm` (CPU)
   - Frontend: `tvm.relax.frontend.torch.from_exported_program`
   
   ### Steps to reproduce
   
   ```python
   import torch
   import tvm
   from tvm import relax
   from tvm.relax.frontend.torch import from_exported_program
   
   
   class M(torch.nn.Module):
       def forward(self, x):
           return x.reshape(-1)[: x.numel() // 10 * 10].reshape(-1, 10)
   
   
   m = M()
   x = torch.randn(3)
   
   # eager mode
   out = m(x)
   print("shape:", tuple(out.shape))   
   
   # compile mode
   ep = torch.export.export(m, (x,))
   mod = from_exported_program(ep, keep_params_as_input=True, unwrap_unit_return_tuple=True)
   mod, _ = relax.frontend.detach_params(mod)
   tvm.compile(mod, target=tvm.target.Target("llvm"))   
   ```
   
   ### Triage
   * needs-triage
   


-- 
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: discuss-archive-unsubscribe@tvm.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [I] [Bug] [Relax] `InternalError: Divide by zero` when compiling a `reshape` that yields a 0-sized dimension [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on issue #19922:
URL: https://github.com/apache/tvm/issues/19922#issuecomment-4891651371

   Hi @raindrops-0199 
   
   Thanks for heads-up! This looks like it might be related to issue#17745


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [I] [Bug] [Relax] `InternalError: Divide by zero` when compiling a `reshape` that yields a 0-sized dimension [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on issue #19922:
URL: https://github.com/apache/tvm/issues/19922#issuecomment-4912551291

   Hi @raindrops-0199 
   PR #19958 is currently tracking this issue. You can give it a try and let us know if it resolves the problem for you.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [I] [Bug] [Relax] `InternalError: Divide by zero` when compiling a `reshape` that yields a 0-sized dimension [tvm]

Posted by "raindrops-0199 (via GitHub)" <gi...@apache.org>.
raindrops-0199 commented on issue #19922:
URL: https://github.com/apache/tvm/issues/19922#issuecomment-4891829472

   Hi @cchung100m 
   
   Thanks for pointing this out! I wasn’t aware of #17745 when I filed this issue, but it does look closely related. Hopefully, the minimal reproducer here can provide some additional help for further investigation.
   


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [I] [Bug] [Relax] `InternalError: Divide by zero` when compiling a `reshape` that yields a 0-sized dimension [tvm]

Posted by "viiccwen (via GitHub)" <gi...@apache.org>.
viiccwen commented on issue #19922:
URL: https://github.com/apache/tvm/issues/19922#issuecomment-4980493913

   @cchung100m I already tested and it solved, can be safely closed.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [I] [Bug] [Relax] `InternalError: Divide by zero` when compiling a `reshape` that yields a 0-sized dimension [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on issue #19922:
URL: https://github.com/apache/tvm/issues/19922#issuecomment-5076543257

   Thanks to @viiccwen 


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org