[MIGraphX EP] Model cache reuses a compiled program for a different input shape
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 58/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend, machine-learning
Hướng nghiên cứu
Start in migraphx_execution_provider.cc at make_hash and the no_input_shape branch in Compute, as identified in the issue. Check how input tensor dimensions contribute to the cache key on the first run and how that key is used to name the cache file. Reproduce with the supplied symbolic-shape model and compare cached runs against uncached runs; done means each input shape loads or compiles the matching program across sessions.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the issue
With migraphx_model_cache_dir set, the MIGraphX EP can load a program that was compiled for a different input shape. For a model with symbolic input dimensions, the EP then returns output with the old shape instead of recompiling. Without a cache directory, the same sequence of runs is correct.
Because the cache is on disk, the wrong program keeps being loaded in later processes until the file is deleted.
With real image models at around 263x910, returning to an earlier shape within a session also failed on one model with HIP failure 700: an illegal memory access was encountered.
Expected: each distinct input shape gets its own cached program, or a recompile.
Cause (line numbers from migraphx_execution_provider.cc at d93f5446):
make_hash(line 1297) passesv.size()as MurmurHash3's length, which is a byte count. For thestd::vector<std::int64_t>of shape values, only the first few bytes are hashed, so height and width don't affect the result.- On the first
Computeof a model with symbolic dimensions, theno_input_shapebranch (line 1446) doesn't fillinput_shapes; only theelsebranch does (line 1485). The cache file name at line 1497 is then built from an empty list, so every first run of that model gets the same name.
Fixing make_hash alone doesn't resolve the cross-session case, because of the second problem.
Possible fix: pass v.size() * sizeof(*v.data()) in make_hash, and populate input_shapes from the actual input tensors in the no_input_shape branch before the cache file name is built.
Related: ROCm/onnxruntime#237, ROCm/onnxruntime#245 and ROCm/onnxruntime#246 describe the make_hash part against AMD's fork.
To reproduce
import tempfile
import numpy as np
import onnx
import onnxruntime as ort
from onnx import TensorProto, helper
graph = helper.make_graph(
[helper.make_node("Mul", ["x", "two"], ["y"])],
"g",
[helper.make_tensor_value_info("x", TensorProto.FLOAT, [1, 1, "h", "w"])],
[helper.make_tensor_value_info("y", TensorProto.FLOAT, [1, 1, "h", "w"])],
[helper.make_tensor("two", TensorProto.FLOAT, [], [2.0])],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)])
model.ir_version = 10
model_path = tempfile.mkdtemp() + "/m.onnx"
onnx.save(model, model_path)
def session(cache_dir=None):
options = {"migraphx_model_cache_dir": cache_dir} if cache_dir else {}
return ort.InferenceSession(model_path, providers=[("MIGraphXExecutionProvider", options)])
def run(s, h, w):
return s.run(None, {"x": np.ones([1, 1, h, w], dtype=np.float32)})[0].shape
print("no cache, new sessions: ", [run(session(), h, w) for h, w in ((4, 8), (6, 8), (4, 10))])
cache = tempfile.mkdtemp()
print("shared cache, new sessions:", [run(session(cache), h, w) for h, w in ((4, 8), (6, 8), (4, 10))])
cache = tempfile.mkdtemp()
s = session(cache)
print("shared cache, one session: ", [run(s, h, w) for h, w in ((4, 8), (6, 8), (4, 8))])
Output:
no cache, new sessions: [(1, 1, 4, 8), (1, 1, 6, 8), (1, 1, 4, 10)]
shared cache, new sessions: [(1, 1, 4, 8), (1, 1, 4, 8), (1, 1, 4, 8)]
shared cache, one session: [(1, 1, 4, 8), (1, 1, 6, 8), (1, 1, 6, 8)]
Urgency
Not blocking me: I can work around it by using a separate cache directory per input shape. It does produce wrong output with no error for anyone using one cache directory with more than one input size.
System information
- Platform: Linux
- OS Version: Gentoo Linux
- ONNX Runtime Installation: Other / Unknown (the
onnxruntime-migraphx1.27.1 wheel on PyPI, a community build of this repository's source) - ONNX Runtime Version or Commit ID: 1.27.1 (the code described above is unchanged at d93f5446)
- ONNX Runtime API: Python
- Architecture: X64
- Execution Provider: MIGraphX
- Execution Provider Library Version: ROCm 7.2.0, MIGraphX 2.15 built from source (Radeon VII, gfx906)
- Ngôn ngữ chính
- C++
- Star
- 22.2k
- Fork
- 4.4k
- Merge trung bình
- 3 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 278
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/onnxruntime
-
[Feature Request] [Web] Expose kvCacheQuantizationBits in the onnxruntime-web WebGPU EP optionsĐang mởep:WebGPU platform:web quantization
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
microsoft/onnxruntime#33752 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
platform:web
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
microsoft/onnxruntime#33570 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
C++ tests fail to compileCó thể đã có người làm @winstonwen727 đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
microsoft/onnxruntime#33430 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/onnxruntime#33300 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
LayerNormFusionL2 removes a public duplicate Sub outputCó thể đã có người làm @Yuhx141 đã nhận 40 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/onnxruntime#32953 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/onnxruntime
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
DarkCastleMUD/DarkCastle#283 ·
-
Toggle state is unclearĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
-priority- blocked good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
scribe-org/Scribe-Android#761 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
SCIInstitute/SCIRun#2931 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 5 ngày