Skip to content

Commit e05b196

Browse files
subhamsoni-googlecopybara-github
authored andcommitted
Add named arguments to the pywrap_profiler_plugin functions.
PiperOrigin-RevId: 851212029
1 parent 02f6a0a commit e05b196

File tree

4 files changed

+81
-51
lines changed

4 files changed

+81
-51
lines changed

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ http_archive(
6767
name = "xla",
6868
patch_args = ["-p1"],
6969
patches = ["//third_party:xla.patch"],
70-
sha256 = "fb110de1feb871be75ea4ea4c529165ac5feaac61f9a96855d7420f843a61e5d",
71-
strip_prefix = "xla-9e7a6358af8fec8d73174bfc6cff2e180bb8fdf6",
70+
sha256 = "40c0ab46b7b9f1ccaa063aa5cd3c062e0a7b74e8885250bd6803efc1aa09890b",
71+
strip_prefix = "xla-990044eaf27699fc33c874f181c6ff22441b0195",
7272
urls = [
73-
"https://github.com/openxla/xla/archive/9e7a6358af8fec8d73174bfc6cff2e180bb8fdf6.zip",
73+
"https://github.com/openxla/xla/archive/990044eaf27699fc33c874f181c6ff22441b0195.zip",
7474
],
7575
)
7676

third_party/xla.patch

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
diff --git a/workspace1.bzl b/workspace1.bzl
2-
index 05121708fc..82e2b0e14d 100644
32
--- a/workspace1.bzl
43
+++ b/workspace1.bzl
5-
@@ -2,7 +2,7 @@
6-
7-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
@@ -3,7 +3,7 @@
5+
86
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
97
-load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
108
+load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies")
119
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
10+
load("//third_party:repo.bzl", "tf_http_archive", "tf_mirror_urls")
1211
load("//third_party/llvm:setup.bzl", "llvm_setup")
13-
14-
@@ -13,7 +13,7 @@ def workspace():
12+
@@ -14,7 +14,7 @@ def workspace():
1513
native.register_toolchains("@local_config_python//:py_toolchain")
1614
rules_pkg_dependencies()
17-
15+
1816
- closure_repositories()
1917
+ rules_closure_dependencies()
20-
21-
http_archive(
18+
19+
tf_http_archive(
2220
name = "bazel_toolchains",
23-
2421
diff --git a/tools/toolchains/python/python_repo.bzl b/tools/toolchains/python/python_repo.bzl
2522
index 47fe64d7b7b..a01a1f19c8b 100644
2623
--- a/tools/toolchains/python/python_repo.bzl

xprof/pywrap/_pywrap_profiler_plugin.pyi

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,29 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16-
def monitor(arg0: str, arg1: int, arg2: int, arg3: bool) -> str: ...
17-
def trace(arg0: str, arg1: str, arg2: str, arg3: bool, arg4: int, arg5: int, arg6: dict) -> None: ...
18-
def xspace_to_tools_data(arg0: list, arg1: str, arg2: dict = ...) -> tuple: ...
19-
def xspace_to_tools_data_from_byte_string(arg0: list, arg1: list, arg2: str, arg3: dict) -> tuple: ...
16+
def monitor(
17+
service_addr: str,
18+
duration_ms: int,
19+
monitoring_level: int,
20+
display_timestamp: bool,
21+
) -> str: ...
22+
def trace(
23+
service_addr: str,
24+
logdir: str,
25+
worker_list: str,
26+
include_dataset_ops: bool,
27+
duration_ms: int,
28+
num_tracing_attempts: int,
29+
options: dict,
30+
) -> None: ...
31+
def xspace_to_tools_data(
32+
xspace_path_list: list, tool_name: str, options: dict = ...
33+
) -> tuple: ...
34+
def xspace_to_tools_data_from_byte_string(
35+
xspace_string_list: list,
36+
filenames_list: list,
37+
tool_name: str,
38+
options: dict,
39+
) -> tuple: ...
2040
def start_grpc_server(port: int) -> None: ...
2141
def initialize_stubs(worker_service_addresses: str) -> None: ...
22-

xprof/pywrap/pywrap_profiler_plugin.cc

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ ToolOptions ToolOptionsFromPythonDict(const py::dict& dictionary) {
5757

5858
PYBIND11_MODULE(_pywrap_profiler_plugin, m) {
5959
m.def(
60-
"trace", [](const char* service_addr, const char* logdir,
61-
const char* worker_list, bool include_dataset_ops,
62-
int duration_ms, int num_tracing_attempts, py::dict options) {
60+
"trace",
61+
[](const char* service_addr, const char* logdir, const char* worker_list,
62+
bool include_dataset_ops, int duration_ms, int num_tracing_attempts,
63+
py::dict options) {
6364
absl::Status status;
6465
ToolOptions tool_options = ToolOptionsFromPythonDict(options);
6566
{
@@ -70,22 +71,29 @@ PYBIND11_MODULE(_pywrap_profiler_plugin, m) {
7071
}
7172
// Py_INCREF and Py_DECREF must be called holding the GIL.
7273
xla::ThrowIfError(status);
73-
});
74-
75-
m.def("monitor", [](const char* service_addr, int duration_ms,
76-
int monitoring_level, bool display_timestamp) {
77-
std::string content;
78-
absl::Status status;
79-
{
80-
py::gil_scoped_release release;
81-
status =
82-
xprof::pywrap::Monitor(service_addr, duration_ms, monitoring_level,
83-
display_timestamp, &content);
84-
}
85-
// Py_INCREF and Py_DECREF must be called holding the GIL.
86-
xla::ThrowIfError(status);
87-
return content;
88-
});
74+
},
75+
py::arg("service_addr"), py::arg("logdir"), py::arg("worker_list"),
76+
py::arg("include_dataset_ops"), py::arg("duration_ms"),
77+
py::arg("num_tracing_attempts"), py::arg("options"));
78+
79+
m.def(
80+
"monitor",
81+
[](const char* service_addr, int duration_ms, int monitoring_level,
82+
bool display_timestamp) {
83+
std::string content;
84+
absl::Status status;
85+
{
86+
py::gil_scoped_release release;
87+
status = xprof::pywrap::Monitor(service_addr, duration_ms,
88+
monitoring_level, display_timestamp,
89+
&content);
90+
}
91+
// Py_INCREF and Py_DECREF must be called holding the GIL.
92+
xla::ThrowIfError(status);
93+
return content;
94+
},
95+
py::arg("service_addr"), py::arg("duration_ms"),
96+
py::arg("monitoring_level"), py::arg("display_timestamp"));
8997

9098
m.def(
9199
"xspace_to_tools_data",
@@ -98,8 +106,7 @@ PYBIND11_MODULE(_pywrap_profiler_plugin, m) {
98106
xspace_paths.push_back(xspace_path);
99107
}
100108
std::string tool_name = std::string(py_tool_name);
101-
ToolOptions tool_options =
102-
ToolOptionsFromPythonDict(options);
109+
ToolOptions tool_options = ToolOptionsFromPythonDict(options);
103110
absl::StatusOr<std::pair<std::string, bool>> result;
104111
{
105112
py::gil_scoped_release release;
@@ -113,7 +120,8 @@ PYBIND11_MODULE(_pywrap_profiler_plugin, m) {
113120
return py::make_tuple(py::bytes(result->first),
114121
py::bool_(result->second));
115122
},
116-
py::arg(), py::arg(), py::arg() = py::dict());
123+
py::arg("xspace_path_list"), py::arg("tool_name"),
124+
py::arg("options") = py::dict());
117125

118126
m.def(
119127
"xspace_to_tools_data_from_byte_string",
@@ -132,8 +140,7 @@ PYBIND11_MODULE(_pywrap_profiler_plugin, m) {
132140
}
133141

134142
std::string tool_name = std::string(py_tool_name);
135-
ToolOptions tool_options =
136-
ToolOptionsFromPythonDict(options);
143+
ToolOptions tool_options = ToolOptionsFromPythonDict(options);
137144

138145
absl::StatusOr<std::pair<std::string, bool>> result;
139146
{
@@ -148,17 +155,24 @@ PYBIND11_MODULE(_pywrap_profiler_plugin, m) {
148155
return py::make_tuple(py::bytes(result->first),
149156
py::bool_(result->second));
150157
},
151-
py::arg(), py::arg(), py::arg(), py::arg() = py::dict());
158+
py::arg("xspace_string_list"), py::arg("filenames_list"),
159+
py::arg("tool_name"), py::arg("options") = py::dict());
152160

153-
m.def("start_grpc_server", [](int port) {
154-
py::gil_scoped_release release;
155-
xprof::pywrap::StartGrpcServer(port);
156-
});
161+
m.def(
162+
"start_grpc_server",
163+
[](int port) {
164+
py::gil_scoped_release release;
165+
xprof::pywrap::StartGrpcServer(port);
166+
},
167+
py::arg("port"));
157168

158-
m.def("initialize_stubs", [](const std::string& worker_service_addresses) {
159-
py::gil_scoped_release release;
160-
xprof::profiler::InitializeStubs(worker_service_addresses);
161-
});
169+
m.def(
170+
"initialize_stubs",
171+
[](const std::string& worker_service_addresses) {
172+
py::gil_scoped_release release;
173+
xprof::profiler::InitializeStubs(worker_service_addresses);
174+
},
175+
py::arg("worker_service_addresses"));
162176
};
163177

164178
} // namespace

0 commit comments

Comments
 (0)