-
Notifications
You must be signed in to change notification settings - Fork 6k
[Cpp API Compatibility] Complement ScalarType #78581
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // The file has been adapted from pytorch project | ||
| // Licensed under BSD-style license - | ||
| // https://github.com/pytorch/pytorch/blob/main/LICENSE | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace c10 { | ||
|
|
||
| /// Defines the Float4_e2m1fn_x2 type (4-bit floating-point, two elements packed | ||
| /// into one byte). This is the FP4 dtype from the OCP MX format spec | ||
| /// (https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf, | ||
| /// Section 5.3.3) | ||
| /// | ||
| /// Given two high precision values val0 and val1, here is the | ||
| /// binary configuration of their packed representation, from MSB to LSB: | ||
| /// | ||
| /// original value | val1 : val0 | ||
| /// ======================================== | ||
| /// bit index (MSB==7, LSB==0) | 7654 : 3210 | ||
| /// sign/exponent/mantissa | seem : seem | ||
|
|
||
| struct alignas(1) Float4_e2m1fn_x2 { | ||
| uint8_t val_; | ||
| Float4_e2m1fn_x2() = default; | ||
| explicit constexpr Float4_e2m1fn_x2(uint8_t val) : val_(val) {} | ||
| }; | ||
|
|
||
| /// Comparison operators | ||
| inline bool operator==(const Float4_e2m1fn_x2& a, const Float4_e2m1fn_x2& b) { | ||
| return a.val_ == b.val_; | ||
| } | ||
|
|
||
| inline bool operator!=(const Float4_e2m1fn_x2& a, const Float4_e2m1fn_x2& b) { | ||
| return a.val_ != b.val_; | ||
| } | ||
|
|
||
| } // namespace c10 | ||
|
|
||
| namespace at { | ||
| using c10::Float4_e2m1fn_x2; | ||
| using c10::operator!=; | ||
| using c10::operator==; | ||
| } // namespace at | ||
|
|
||
| namespace torch { | ||
| using c10::Float4_e2m1fn_x2; | ||
| using c10::operator!=; | ||
| using c10::operator==; | ||
| } // namespace torch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // The file has been adapted from pytorch project | ||
| // Licensed under BSD-style license - | ||
| // https://github.com/pytorch/pytorch/blob/main/LICENSE | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace c10 { | ||
|
|
||
| struct Float8_e4m3fnuz { | ||
| constexpr Float8_e4m3fnuz() = default; | ||
| explicit constexpr Float8_e4m3fnuz(uint8_t value) : x(value) {} | ||
|
|
||
| uint8_t x{0}; | ||
| }; | ||
|
|
||
| } // namespace c10 | ||
|
|
||
| namespace at { | ||
| using c10::Float8_e4m3fnuz; | ||
| } // namespace at | ||
|
|
||
| namespace torch { | ||
| using c10::Float8_e4m3fnuz; | ||
| } // namespace torch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // The file has been adapted from pytorch project | ||
| // Licensed under BSD-style license - | ||
| // https://github.com/pytorch/pytorch/blob/main/LICENSE | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace c10 { | ||
|
|
||
| struct Float8_e5m2fnuz { | ||
| constexpr Float8_e5m2fnuz() = default; | ||
| explicit constexpr Float8_e5m2fnuz(uint8_t value) : x(value) {} | ||
|
|
||
| uint8_t x{0}; | ||
| }; | ||
|
|
||
| } // namespace c10 | ||
|
|
||
| namespace at { | ||
| using c10::Float8_e5m2fnuz; | ||
| } // namespace at | ||
|
|
||
| namespace torch { | ||
| using c10::Float8_e5m2fnuz; | ||
| } // namespace torch |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@ShigureNyako 单独提一个 PR 把 repo 里所有这样的声明都参考这里的改动改一下吧
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.
收到。我会把这类
adapted from PyTorch参考声明的补齐整理成单独 PR 跟进,避免把 repo-wide 清理和这次ScalarType兼容性改动混在一起。当前这个 PR 我这边保持通过,后续会单独开任务处理。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.
已处理,单独提了 repo-wide 清理 PR #78590,按这次
ScalarType.h/ 新增 compat wrapper 的声明格式统一了现有 malformed adapted-from-PyTorch reference blocks。这个跟进 PR 只改参考声明注释,不涉及 ABI、dispatch 行为或调用方式变化。