-
Notifications
You must be signed in to change notification settings - Fork 657
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
Remove python function wrapper. #6012
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b6635f6
Remove python function wrapper.
hjchen2 5391b82
Increase ref
hjchen2 3915f23
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot e7fd288
Fix doc test
hjchen2 668d8df
Merge branch 'master' into dev_rm_python_function_wrapper
hjchen2 7316f90
Merge branch 'master' into dev_rm_python_function_wrapper
hjchen2 48c9806
Update python/oneflow/framework/docstr/utils.py
hjchen2 1bdc162
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot a2b9c18
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot fb3a7bd
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot 1a676cc
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot 913a1a0
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot 46cf7e2
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot eb4f51e
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot 65a1160
Merge branch 'master' into dev_rm_python_function_wrapper
oneflow-ci-bot File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2020 The OneFlow 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. | ||
*/ | ||
#include <pybind11/pybind11.h> | ||
|
||
#include "oneflow/api/python/of_api_registry.h" | ||
#include "oneflow/api/python/framework/throw.h" | ||
|
||
namespace py = pybind11; | ||
|
||
namespace oneflow { | ||
|
||
py::object AddFunctionDoc(py::object f, const std::string& doc_string) { | ||
static std::vector<std::string> all_doc_strings; | ||
all_doc_strings.emplace_back(doc_string); | ||
const char* doc_str = all_doc_strings.back().c_str(); | ||
PyObject* obj = f.ptr(); | ||
if (PyCFunction_Check(obj)) { | ||
auto* f = (PyCFunctionObject*)obj; | ||
if (f->m_ml->ml_doc) { | ||
THROW(RuntimeError) << "function " << f->m_ml->ml_name << " already has a docstring."; | ||
} | ||
f->m_ml->ml_doc = doc_str; | ||
} else { | ||
THROW(RuntimeError) << "function is " << Py_TYPE(obj)->tp_name << ", not a valid PyCFunction."; | ||
} | ||
f.inc_ref(); | ||
return f; | ||
} | ||
|
||
} // namespace oneflow | ||
|
||
ONEFLOW_API_PYBIND11_MODULE("", m) { m.def("add_doc", &oneflow::AddFunctionDoc); } |
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,16 @@ | ||
""" | ||
Copyright 2020 The OneFlow 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. | ||
""" | ||
from oneflow._oneflow_internal.F import * | ||
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -121,7 +121,11 @@ | |
namespace functional = one::functional; | ||
|
||
ONEFLOW_API_PYBIND11_MODULE("F", m) {{ | ||
py::options options; | ||
options.disable_function_signatures(); | ||
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. 禁止pybind自动生成doc |
||
|
||
{1} | ||
options.enable_function_signatures(); | ||
}} | ||
|
||
}} // namespace oneflow | ||
|
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.
这个
F
名字空间,其实作用是对应了 torch 中的torch._C
吧?我们是未来会改成
_C
吗?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.
目前感觉没太大必要,和torch的
_C
也不是完全对应。torch的接口导出比较分散,有些直接导出到torch,有些是torch._C
,我们都统一到F
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.
好的。