Skip to content

A few fixes to the profiler IPython magics#7108

Merged
rapids-bot[bot] merged 1 commit intorapidsai:branch-25.10from
jcrist:fixup-cuml-accel-profiler-magics
Aug 13, 2025
Merged

A few fixes to the profiler IPython magics#7108
rapids-bot[bot] merged 1 commit intorapidsai:branch-25.10from
jcrist:fixup-cuml-accel-profiler-magics

Conversation

@jcrist
Copy link
Copy Markdown
Member

@jcrist jcrist commented Aug 12, 2025

This fixes several bugs and UX rough edges with the cuml.accel IPython magics:

  • For cells with outputs, still render the output when run under the profiler magics.
  • Ensure composing the profiler magics in either order works appropriately. This means you can combine both profilers (or other cell magics like %%time) in the same cell without issue.
  • Ensure that code from previous cells isn't mistakenly traced, leading to incorrect measurements.
  • Make matching the source to executed lines more robust to IPython source transformations.
  • Don't render the reports for invalid cells (e.g. SyntaxError), but do for execution errors.
  • A few small formatting niceties.

The first 2 issues were found and reported by others through internal usage, the rest I found while debugging and testing.

- For cells with outputs, still render the output when run under the
  profiler magics.
- Ensure composing the profiler magics in either order works
  appropriately.
- Ensure that code from previous cells isn't mistakenly traced, leading
  to incorrect measurements.
- Make matching the source to executed lines more robust to IPython
  source transformations.
- A few small formatting nicities.
@jcrist jcrist self-assigned this Aug 12, 2025
@jcrist jcrist requested a review from a team as a code owner August 12, 2025 20:35
@jcrist jcrist added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change cuml-accel Issues related to cuml.accel labels Aug 12, 2025
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Aug 12, 2025
Copy link
Copy Markdown
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kicked the tyres on this in both jupyter (classic) notebook and IPython proper. Can't break it and only found things that worked as expected and/or as the PR comment says they should.

cell = self.shell.transform_cell(cell)
exec_source(cell, self.shell.user_ns, line_profile=True)

profiler = profilers.LineProfiler(source=source, filename=None)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education: I was expecting source=cell, what did I miss?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point cell is any remaining magics + source (and then transformed to standard python code). In the absence of remaining magics they're the same, but in their presence source should be what's finally exec'd by the nested cell magic. It's a bit convoluted, but it works.

@jcrist
Copy link
Copy Markdown
Member Author

jcrist commented Aug 13, 2025

/merge

@rapids-bot rapids-bot Bot merged commit 8cae6e2 into rapidsai:branch-25.10 Aug 13, 2025
75 checks passed
@jcrist jcrist deleted the fixup-cuml-accel-profiler-magics branch August 13, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuml-accel Issues related to cuml.accel Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants