-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[SOT][FasterGuard] ShapeMatchGuard
support dynamic shape
#72564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -156,14 +156,13 @@ class DtypeMatchGuard : public GuardBase { | |||||
|
||||||
class ShapeMatchGuard : public GuardBase { | ||||||
public: | ||||||
explicit ShapeMatchGuard(const std::vector<std::optional<int64_t>>& shape) | ||||||
: expected_(shape) {} | ||||||
|
||||||
explicit ShapeMatchGuard(const std::vector<py::object>& shape) { | ||||||
expected_.resize(shape.size()); | ||||||
for (size_t i = 0; i < shape.size(); ++i) { | ||||||
if (py::isinstance<py::int_>(shape[i]) && shape[i].cast<int64_t>() > 0) { | ||||||
expected_[i] = std::make_optional(shape[i].cast<int64_t>()); | ||||||
expected_.reserve(shape.size()); | ||||||
for (const auto& s : shape) { | ||||||
if (py::isinstance<py::int_>(s)) { | ||||||
expected_.push_back(s.cast<int64_t>()); | ||||||
} else { | ||||||
expected_.push_back(-1); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Consider replacing the magic number -1 with a named constant (e.g., kDynamicDimension) to improve code readability and maintainability.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么把原来能够用类型保护的 如果觉得 去掉类型安全绝对是很蠢的操作,没错说的就是整个框架用 -1 表示 dynamic dim 这种操作 |
||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -172,7 +171,7 @@ class ShapeMatchGuard : public GuardBase { | |||||
std::string get_guard_name() const override { return "ShapeMatchGuard"; } | ||||||
|
||||||
private: | ||||||
std::vector<std::optional<int64_t>> expected_; | ||||||
std::vector<int64_t> expected_; | ||||||
}; | ||||||
|
||||||
class AttributeMatchGuard : public GuardBase { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Adding a brief comment clarifying that -1 is used as a sentinel for dynamic dimensions would help maintainers understand the control flow.
Copilot uses AI. Check for mistakes.