[Bug] [Relax][ONNX] Dropout ignores training_mode and returns unscaled input

Đang mở
#20,934 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
77/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, machine-learning

Hướng nghiên cứu

The issue points to the ONNX converter in python/tvm/relax/frontend/onnx/onnx_frontend.py, around lines 3736–3754. Read the Dropout conversion and trace how it handles the ratio and optional training_mode input; then run the reproduction or add a focused test for Dropout-13. Done means inference still returns the input and training mode produces only 0 or 2 for an input of ones with ratio 0.5.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

needs-triage type: bug
Expected behavior

For Dropout-13, training_mode=true and ratio=0.5, every output for an input of ones must be either 0 or 2. This contract does not require matching random draws.

Actual behavior

Inference mode passes. Training mode also returns all ones: 64/64 elements violate the contract. The converter reads ratio but never uses the third input, training_mode.

Environment

TVM 0.28.dev0, LLVM 18.1.3, Linux x86_64; Python 3.12.3, NumPy 2.5.4, ONNX 1.22.0. Installed binary build revision is unknown. Current main was inspected statically, not rebuilt.

Steps to reproduce
import numpy as np
import onnx
import tvm
from onnx import TensorProto as T, helper as h, numpy_helper as nh
from onnx.reference import ReferenceEvaluator
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx

x = np.ones((64,), dtype="float32")
for training in [False, True]:
    model = h.make_model(h.make_graph([
        h.make_node("Dropout", ["x", "ratio", "training"], ["y"])], "dropout",
        [h.make_tensor_value_info("x", T.FLOAT, x.shape)],
        [h.make_tensor_value_info("y", T.FLOAT, x.shape)],
        [nh.from_array(np.array(.5, dtype="float32"), "ratio"),
         nh.from_array(np.array(training, dtype="bool"), "training")]),
        opset_imports=[h.make_opsetid("", 13)], ir_version=10)
    onnx.checker.check_model(model, full_check=True)
    expected = ReferenceEvaluator(model).run(None, {"x": x})[0]
    mod = from_onnx(model, keep_params_in_input=False)
    vm = relax.VirtualMachine(relax.build(mod, target="llvm"), tvm.cpu())
    actual = vm["main"](tvm.runtime.tensor(x)).numpy()
    if not training:
        np.testing.assert_array_equal(expected, x)
        np.testing.assert_array_equal(actual, x)
        print("inference control passed")
    else:
        assert np.all((expected == 0) | (expected == 2))
        np.testing.assert_array_equal(actual, x)
        violations = np.count_nonzero((actual != 0) & (actual != 2))
        assert violations == x.size
        print("training contract violations:", violations, "of", x.size)
Triage
  • needs-triage
Ngôn ngữ chính
Python
Star
13.9k
Fork
4.1k
Merge trung bình
4 ngày 22 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/tvm

Tất cả issue của apache/tvm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.