-
Notifications
You must be signed in to change notification settings - Fork 1k
Prune python tensor #5596
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
Prune python tensor #5596
Conversation
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
| from oneflow.compatible.single_client.core.job import ( |
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.
用 oneflow/python/framework/tensor.py 的内容覆盖了这个文件的原内容。因为它们共用了一个 _oneflow_internal
| namespace { | ||
| static PyObject* py_kernels_dic = nullptr; | ||
|
|
||
| void OFDataTypeToNumpyType(DataType of_data_type, int* out_numpy_type) { |
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.
这两个方法移动到了 oneflow/extension/python/numpy.h 里并做了修改
Signed-off-by: daquexian <[email protected]>
f423439 to
003787a
Compare
Signed-off-by: daquexian <[email protected]>
003787a to
ffa1047
Compare
| Tensor.normal_ = _normal | ||
| Tensor.fill_ = _fill | ||
| Tensor._placement_scope = _placement_scope | ||
| Tensor.copy_ = _copy |
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.
c++ tensor 类的一些方法在 python 层注入,暂时不着急全部重写到 c++
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
| @@ -1,7 +1,7 @@ | |||
| include(FetchContent) | |||
| set(PYBIND11_TAR_URL https://github.com/pybind/pybind11/archive/v2.6.0.zip) | |||
| set(PYBIND11_TAR_URL https://github.com/pybind/pybind11/archive/v2.7.0.zip) | |||
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.
升级 pybind11 把这个修复 gcc 4 编译错误的 pr 包含进来 pybind/pybind11#2956
wyg1997
left a comment
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.
Parameter的构造函数里是不是忘处理了?
| } else { | ||
| return MakeLocalTensorByNumpy(arg, desired_dtype, device, requires_grad); | ||
| } | ||
| } else { |
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.
这里需要和Pytorch那样,如果参数检察不正确,把所有的合法参数都打印出来给个提示吗?
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.
感觉可以 😂
Signed-off-by: daquexian <[email protected]>
0e80934 to
a87b836
Compare
Signed-off-by: daquexian <[email protected]>
| std::string type; | ||
| int device_id = -1; | ||
| ParsingDeviceTag(type_and_id, &type, &device_id).GetOrThrow(); | ||
| if (device_id == -1) { device_id = 0; } | ||
| return MakeDevice(type, device_id); |
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.
记得新开一个issue,让新手对这里做优化。用thread_local作缓存。
oneflow/core/framework/tensor.h
Outdated
| } | ||
|
|
||
| bool requires_grad() const override { return tensor_->requires_grad(); } | ||
| bool is_leaf() const override { return tensor_->is_leaf(); } |
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.
是不是应该直接返回true呢?
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.
是的,已修改,同时通过让 Parameter 继承 TensorIf,也实现了 Parameter 有独立的 grad_fn
| user_op::TensorDesc* mut_tensor_meta() override { return tensor_->mut_tensor_meta(); } | ||
|
|
||
| Maybe<MirroredTensor> AsMirroredTensor() override { | ||
| if (const auto& mirrored_tensor = std::dynamic_pointer_cast<MirroredTensor>(tensor_)) { |
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.
这语法是c++11所能支持的吗?
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.
是的,这个和 c++17 的 if (int x = 0; x < 1) 不是同一个语法
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.
哦哦。我才注意到两者的区别,那我还把很多的宏写复杂了。
…d missing get_device method, remove out-dated methods in docs Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
Signed-off-by: daquexian <[email protected]>
…into prune_python_tensor
Signed-off-by: daquexian <[email protected]>
Speed stats: |
将 python 的 Tensor 类删除,逻辑转移到 c++