Repository navigation
[mkldnn][17/N] Port ideep's primitive cache and attr_t into ATen - #205977
frost-intel wants to merge 4 commits into
Conversation
[ghstack-poisoned]
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (9): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/205977
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 84794a9 with merge base 47eb5c6 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Automated review of 31e807f: nothing blocking; ready for human review.
The PR ports ideep's primitive cache (lru_cache, computation_cache, to_bytes/create_key) and ideep::attr_t into ATen as detail/PrimitiveCache.h and detail/Attr.h, and moves every ATen use to at::native::mkldnn::Attr. The review recommends Approve and found no blocking problems. Every point it raises is labeled non-blocking, mostly hazards inherited from ideep.
⚪ 9 non-blocking findings
Non-blocking: Attr::operator= overwrites scales_ and zero_points_ only when rhs has them. Assigning a plain attr onto one that already holds scales leaves the old maps in place. Those stale maps then feed to_bytes (the primitive-cache key) and operator ideep::attr_t() (the reorder scales), so the cache key and reorders would disagree with the real oneDNN handle. No current caller hits this: the reassignments in Conv.cpp:129/132, Matmul.cpp:37/301 and InnerProduct.cpp:105 all run on a fresh object. Reordering any one of them would make it a silent bug. Fix: reset the maps (scales_.reset() / zero_points_.reset()) when rhs has none.
Non-blocking: LRU_CACHE_CAPACITY is checked for being positive only under #ifndef NDEBUG. In release builds, a value of 0 or a non-numeric value calls resize(0). insert then pushes the node, the trim loop pops it, and insert returns vlist_.begin(), which equals end(). fetch_or_create dereferences that iterator: undefined behaviour, most likely a crash. A negative value wraps to a huge size_t, so the cache becomes unbounded. Fix: read the variable with c10::utils::get_env (c10/util/env.h) instead of std::getenv, parse it once, and TORCH_CHECK(capacity > 0, ...) in all builds.
Non-blocking: this note is stale. It says scales and zero points are "not encoded so far" and that the cache is "supposed to use in convolution only". Lines 354-370 do encode scales and zero points, and the cache now also serves deconv, inner product and matmul.
Non-blocking: non_negitive_output is a typo. It is new ATen API with one caller (detail/Conv.cpp:72), so renaming it now is cheap.
Non-blocking: fuse_relu is marked // Deprecated, yet every ATen relu call site uses it (Utils.cpp, qlinear.cpp, qlinear_dynamic.cpp, qconv.cpp, OpContext.h, OnednnUtils.h). Either move the callers to fuse_relu_v2 or drop the label. The same applies to fuse_gelu (line 140), which Utils.cpp:131 uses.
Non-blocking: lines 38 and 58-62 add implicit converting constructors. Attr(const dnnl::primitive_attr&) shares the oneDNN handle instead of cloning it, and it accepts an ideep::attr_t by slicing, which silently drops that attr's scale and zero-point maps. Attr(dnnl_fpmath_mode_t, ...) lets a bare dnnl_fpmath_mode_* enum convert silently wherever a const Attr& is expected. Neither has a caller in aten/ or torch/csrc, and neither does Attr(int arg, int mask, const std::vector<float>&) at line 41. That contradicts the description's "Unused helpers are not ported." Fix: remove the unused constructors, or at least mark them explicit.
Non-blocking: this adds a second lru_cache. aten/src/ATen/native/mkldnn/xpu/detail/LRUCache.h already provides a header-only at::native::onednn::lru_cache with the same template signature and API (find/insert/resize/clear/end). Consider moving that one somewhere shared and using it for both CPU and XPU rather than keeping two copies.
Non-blocking: this adds a class Attr in at::native::mkldnn that is unrelated to the existing at::native::onednn::Attr (xpu/detail/Attr.h:133). Two unrelated classes with the same name in sibling oneDNN backends will confuse readers.
Non-blocking: the class overload to_bytes(bytestring&, const T arg) takes its argument by value. Attr's copy constructor (Attr.h:34-36) goes through operator=, which runs dnnl_primitive_attr_clone and copies both maps. So every create_key(..., attr, ...) deep-clones the attr on every x86 forward, including cache hits (Conv.cpp:451, InnerProduct.cpp:60, Matmul.cpp:157/383/552, Deconv.cpp:53). Attr also has no move constructor or move assignment, so each std::move(op_attr) into the params structs clones too. This matches ideep, so it is not a regression. Changing the overload to const T& alone does not compile: the unconstrained variadic to_bytes(bytestring&, T&&, Ts&&...) with an empty pack would then win for rvalue class arguments such as weights.get_desc(), so it also needs a sizeof...(Ts) > 0 constraint. Adding defaulted-style move operations to Attr would remove the copies on the params path.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
[ghstack-poisoned]
|
Addressing bot comments:
|
[ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 9 jobs have failed, first few of them are: trunk / win-vs2022-cpu-py3 / test (default, 3, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 1, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 10, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 5, 12, windows.4xlarge.nonephemeral), trunk / win-vs2022-cpu-py3 / test (default, 4, 12, windows.4xlarge.nonephemeral). Blocking jobs that the merge waited on for a Dr.CI or AI CI Advisor classification: 3. Details for Dev Infra teamRaised by workflow job |
[ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 3 mandatory check(s) failed. The first few are:
Dig deeper by viewing the failures on hud |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from ghstack (oldest at bottom):
Linked issue or supporting maintainer
Part of #154444
Supported by @albanD
BC-breaking?
No
Summary (human written only)
This PR ports oneDNN primitive cache and attr_t from ideep to ATen, as well as renames for uses within ATen.
Tests verified the same number of cache-misses for a fixed workload with A/B testing.
Agent details (if applicable)
Developed with assistance from Claude Opus 5.5.