-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DTR 的设计中打算用不同的 device 区分开启/不开启重计算的 tensor(和 torch/xla 做法相同),实现过程中发现 device 相关的代码有些可改进的地方 1. device 无法作为 op 的 attr,master 里用分别设置 device_type 和 device_id 两个 attr 来代替,因此产生了很多无中生有的代码: ```c++ Device a; op.SetAttr(a.device_type(), a.device_id()); Device b = Device::New(op.attr("device_type"), op.attr("device_id")); // 直接 Device b = a 显然更简单 ``` ```c++ inline Maybe<bool> device_equal(const std::string& device_name, const int device_id, Symbol<Device> device) { return (device_name == device->type() && device_id == device->device_id()); } Device a; op.SetAttr(a.device_type(), a.device_id()); if (device_equal(op.attr("device_type"), op.attr("device_id"), b)) // 直接 if (a == b) 显然更简单 ``` 这些冗余代码在给 Device 类增加新参数时也会引起额外的改动量 2. 一些地方错误地使用了 Optional::value_or,如 ```c++ auto device = device_.has_value() ? device_.value_or(Symbol<Device>()) : JUST(input->device()); ``` 3. 一些命名问题,如 `ParsingDeviceTag` 没有用动词(改为 `ParseDeviceTag`)、`Device::ThreadLocalGetOrNew` 和 `Device::New` 功能相同,"New" 的含义互相冲突(删掉了 `Device::ThreadLocalGetOrNew`) 3. operator== 和 operator!= 逻辑重复 --------- Signed-off-by: daquexian <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: oneflow-ci-bot <[email protected]>
- Loading branch information
1 parent
aef9981
commit 4bfef84
Showing
14 changed files
with
132 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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 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,9 @@ | ||
syntax = "proto2"; | ||
package oneflow; | ||
|
||
import "oneflow/core/common/device_type.proto"; | ||
|
||
message DeviceProto { | ||
required DeviceType device_type = 1; | ||
required int64 device_id = 2; | ||
} |
This file contains 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 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 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 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 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 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 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 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 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
Oops, something went wrong.