-
Notifications
You must be signed in to change notification settings - Fork 921
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
Add environment variable to log cudf.pandas fallback calls #16161
Changes from 7 commits
b4795c9
a3e9c59
9f3953e
23a4d26
6ca5ca0
2a4ee9a
9542ec2
aa0d16a
9a906c2
fb6390a
18426b1
53b737c
5689cef
79324f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. | ||
# All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import json | ||
import logging | ||
|
||
# https://docs.python.org/3/howto/logging-cookbook.html#implementing-structured-logging | ||
|
||
|
||
class StructuredMessage: | ||
def __init__(self, debug_type: str, /, **kwargs): | ||
self.debug_type = debug_type | ||
self.kwargs = kwargs | ||
|
||
def __str__(self): | ||
log = {"debug_type": self.debug_type} | ||
return json.dumps({**log, **self.kwargs}) | ||
|
||
|
||
logging.basicConfig( | ||
filename="cudf_pandas_unit_tests_debug.log", level=logging.INFO | ||
) | ||
logger = logging.getLogger() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -930,13 +930,52 @@ def _fast_slow_function_call( | |
"Pandas debugging mode failed. " | ||
f"The exception was {e}." | ||
) | ||
except Exception: | ||
except Exception as err: | ||
with nvtx.annotate( | ||
"EXECUTE_SLOW", | ||
color=_CUDF_PANDAS_NVTX_COLORS["EXECUTE_SLOW"], | ||
domain="cudf_pandas", | ||
): | ||
slow_args, slow_kwargs = _slow_arg(args), _slow_arg(kwargs) | ||
if _env_get_bool("CUDF_PANDAS_SLOW_LOG", False): | ||
from ._logger import StructuredMessage, logger | ||
|
||
def reprify(arg) -> str: | ||
try: | ||
return repr(arg) | ||
except Exception: | ||
return "<REPR FAILED>" | ||
|
||
module = getattr(slow_args[0], "__module__", "") | ||
obj_name = getattr( | ||
slow_args[0], "__name__", type(slow_args[0]).__name__ | ||
) | ||
slow_object = f"{module}.{obj_name}" | ||
# TODO: maybe use inspect.signature to map called args and kwargs | ||
# to their keyword names | ||
called_args = ",".join((reprify(val) for val in slow_args[1])) | ||
if len(slow_args) == 3: | ||
fmt_kwargs = ",".join( | ||
f"{kwarg}={reprify(value)}" | ||
for kwarg, value in slow_args[2].items() | ||
) | ||
called_args = ",".join((called_args, fmt_kwargs)) | ||
passed_kwargs = { | ||
kwarg: reprify(value) | ||
for kwarg, value in slow_args[2].items() | ||
} | ||
else: | ||
passed_kwargs = {} | ||
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. Why are we never looking 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. I think 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.
Correct. Seems like all calls to As commented in #16266 (comment) I am not sure this is exactly a bug |
||
message = StructuredMessage( | ||
"CUDF_PANDAS_SLOW_LOG", | ||
failed_call=f"{slow_object}({called_args})", | ||
exception=type(err).__name__, | ||
exception_message=str(err), | ||
pandas_object=slow_object, | ||
passed_args=called_args, | ||
passed_kwargs=passed_kwargs, | ||
) | ||
logger.info(message) | ||
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. Can we pull all of this logic into the logger, so that we just do:
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. Sure thing. Done. |
||
with disable_module_accelerator(): | ||
result = func(*slow_args, **slow_kwargs) | ||
return _maybe_wrap_result(result, func, *args, **kwargs), fast | ||
|
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.
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.
Thanks. A copy-paste oversight