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 "lrcyyds1 (via GitHub)" <gi...@apache.org> on 2026/08/27 12:17:39 UTC

[I] [Relax] [Bug] Default build silently computes wrong values for match_cast followed by split (second half of split output is misplaced) [tvm]

lrcyyds1 opened a new issue, #20207:
URL: https://github.com/apache/tvm/issues/20207

   Thanks for participating in the TVM community! We use https://discuss.tvm.apache.org/ for any general usage questions and discussions. The issue tracker is used for actionable items such as feature proposals
     discussion, roadmaps, and bug tracking. You are always welcomed to post on the forum first :smile_cat:
   
     ### Expected behavior
   
     For a function that computes `split(-match_cast(x))` and concatenates the
     two halves back, the output should equal `-x`. Building with the default
     pipeline and running should produce numerically correct results (any
     pipeline).
   
     ### Actual behavior
   
     The **default build** (`relax.build(mod, target="llvm")`) silently produces
     wrong values: exactly the **second half of the split output** (columns 8-15
     in the example) is wrong, while the first half is correct. The error is
     structural — the same misplaced values occur for every input (max abs error
     1.58 in the example), not floating-point noise.
   
     Building the same module with the **target default pipeline**
     (`relax.get_default_pipeline(...)`, which includes fusion) produces exactly
     correct results (max abs error 0.0), so the two official build paths
     disagree; the non-fused default path is the wrong one (verified against a
     NumPy reference).
   
     ### Environment
     
     - TVM built from source, commit `5a8dae4d95c55c8fec9246a607a28c3ff54ffe05` (2026-06-24)
     - Linux x86_64, LLVM target
     - Python 3.10
   
     ### Steps to reproduce
   
     ```python
     import numpy as np
     import tvm
     from tvm import relax
   
     bb = relax.BlockBuilder()
     x = relax.Var("x", relax.TensorType([2, 16], "float32"))
     with bb.function("main", params=[x]):
         with bb.dataflow():
             n0 = bb.emit(relax.op.negative(x), name_hint="n0")
             c0 = bb.match_cast(n0, relax.TensorType([2, 16], "float32"),
                                name_hint="c0")
             parts = bb.emit(relax.op.split(c0, [8], axis=-1), name_hint="s")
             a = bb.emit(relax.TupleGetItem(parts, 0), name_hint="a")
             b = bb.emit(relax.TupleGetItem(parts, 1), name_hint="b")
             out = bb.emit(relax.op.concat((a, b), axis=-1), name_hint="out")
             gv = bb.emit_output(out)
         bb.emit_func_output(gv)
     mod = bb.get()
   
     llvm_t = tvm.target.Target("llvm")
   
     # 1) default build: WRONG (max abs diff ~1.58, second half misplaced)
     vm = relax.VirtualMachine(relax.build(mod, target="llvm"), tvm.cpu())
     xnp = np.clip(np.random.RandomState(100).randn(2, 16).astype("float32"), -1, 1)
     got = vm["main"](tvm.runtime.tensor(xnp, tvm.cpu())).numpy()
     print("default  max|out-(-x)| =", np.max(np.abs(got - (-xnp))))   # ~1.58
   
     # 2) target default pipeline (with fusion): CORRECT (0.0)
     exe2 = relax.build(mod, target=llvm_t, exec_mode="compiled",
                        relax_pipeline=relax.get_default_pipeline(llvm_t))
     vm2 = relax.VirtualMachine(exe2, tvm.cpu())
     got2 = vm2["main"](tvm.runtime.tensor(xnp, tvm.cpu())).numpy()
     print("fused    max|out-(-x)| =", np.max(np.abs(got2 - (-xnp))))  # 0.0
   
     Additional notes from minimization:
   
     - The negative is not essential to the semantics, only to exposing the
       misplacement; the trigger is match_cast followed by split (then a
       consumer of the second field).
     - The error is constant across different random inputs, i.e. values are
       structurally misplaced rather than numerically drifted.
     - Applying FuseOps before the default build also makes the result correct,
       so the defect appears to live on the non-fused default-build path.
   
     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] [Relax] [Bug] Default build silently computes wrong values for match_cast followed by split (second half of split output is misplaced) [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex closed issue #20207: [Relax] [Bug] Default build silently computes wrong values for match_cast followed by split (second half of split output is misplaced)
URL: https://github.com/apache/tvm/issues/20207


-- 
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