-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Display traces via post-run hook #11937
Conversation
Documentation preview for 8a3845a will be available when this CircleCI job More info
|
11d2a8e
to
83c4ba7
Compare
@@ -46,40 +88,11 @@ def display_traces(self, traces: List[Trace]): | |||
# this should do nothing if not in an IPython environment |
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.
As mentioned in the PR description, even though this function no longer actually displays anything, I think it makes sense from a developer UX point of view to keep the name as display_traces()
.
|
||
# if the current ipython exec count has changed, then | ||
# we're in a different cell (or rerendering the current | ||
# cell), so we should create a new display handle. | ||
current_exec_count = get_ipython().execution_count | ||
if self._prev_execution_count != current_exec_count: | ||
self._prev_execution_count = current_exec_count | ||
self.traces_to_display = traces_dict | ||
self.display_handle = None | ||
else: | ||
self.traces_to_display.update(traces_dict) | ||
|
||
deduped_trace_list = list(self.traces_to_display.values()) | ||
if self.display_handle: | ||
self.display_handle.update( | ||
self.get_mimebundle(deduped_trace_list), | ||
raw=True, | ||
) | ||
else: | ||
self.display_handle = display( | ||
self.get_mimebundle(deduped_trace_list), | ||
display_id=True, | ||
raw=True, | ||
) | ||
self.traces_to_display.update(traces_dict) | ||
except Exception: | ||
# swallow exceptions. this function is called as | ||
# a side-effect in a few other functions (e.g. log_trace, | ||
# get_traces, search_traces), and we don't want to block | ||
# the core functionality if the display fails. | ||
_logger.debug("Failed to display traces", exc_info=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.
basically moved all this logic into the post-run hook, and removed all logic about tracking execution count, since now we're just guaranteed to execute once per cell
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.
LGTM! Awesome demo :)
# the core functionality if the display fails. | ||
_logger.debug("Failed to register post-run cell display hook", exc_info=True) | ||
|
||
def _display_traces_post_run(self): |
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.
def _display_traces_post_run(self): | |
def _display_traces_post_run(self, result): |
can we add a result
argument?
https://ipython.readthedocs.io/en/stable/config/callbacks.html#ipython-events
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.
pre_run_cell
might be useful to reset self.traces_to_display
or initialize the state.
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.
added result
! as for resetting state, i'm currently just doing it immediately after displaying, so pre_run_cell
should be unnecessary, but we can keep it in mind for future use-cases.
Signed-off-by: Daniel Lok <[email protected]>
Signed-off-by: Daniel Lok <[email protected]>
Signed-off-by: Daniel Lok <[email protected]>
Signed-off-by: Daniel Lok <[email protected]>
Signed-off-by: Daniel Lok <[email protected]>
ed2f91c
to
87cbecc
Compare
Signed-off-by: Daniel Lok <[email protected]>
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
This PR resolves a common complaint that the trace UI does not show up at the end of a cell as expected. To fix this, we register a post-execution hook instead of updating a display handle every time.
I'm keeping the user-facing API as
display_traces()
, because I feel that it would be confusing to change the name to something likeupdate_traces_to_display()
. My main concern is that people will wonder if there's an additionaldisplay()
function that they have to call, but actually it's handled automatically by the post-execution hook.How is this PR tested?
I'll add some automated tests in a bit
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/artifacts
: Artifact stores and artifact loggingarea/build
: Build and test infrastructure for MLflowarea/deployments
: MLflow Deployments client APIs, server, and third-party Deployments integrationsarea/docs
: MLflow documentation pagesarea/examples
: Example codearea/model-registry
: Model Registry service, APIs, and the fluent client calls for Model Registryarea/models
: MLmodel format, model serialization/deserialization, flavorsarea/recipes
: Recipes, Recipe APIs, Recipe configs, Recipe Templatesarea/projects
: MLproject format, project running backendsarea/scoring
: MLflow Model server, model deployment tools, Spark UDFsarea/server-infra
: MLflow Tracking server backendarea/tracking
: Tracking Service, tracking client APIs, autologgingInterface
area/uiux
: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/docker
: Docker use across MLflow's components, such as MLflow Projects and MLflow Modelsarea/sqlalchemy
: Use of SQLAlchemy in the Tracking Service or Model Registryarea/windows
: Windows supportLanguage
language/r
: R APIs and clientslanguage/java
: Java APIs and clientslanguage/new
: Proposals for new client languagesIntegrations
integrations/azure
: Azure and Azure ML integrationsintegrations/sagemaker
: SageMaker integrationsintegrations/databricks
: Databricks integrationsHow should the PR be classified in the release notes? Choose one:
rn/none
- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change
- The PR will be mentioned in the "Breaking Changes" sectionrn/feature
- A new user-facing feature worth mentioning in the release notesrn/bug-fix
- A user-facing bug fix worth mentioning in the release notesrn/documentation
- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yes
should be selected for bug fixes, documentation updates, and other small changes.No
should be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.