Skip to content
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

[tracing] Fix issue where actor/task is defined before ray.init is called #38323

Merged
merged 11 commits into from
Aug 16, 2023

Conversation

edoakes
Copy link
Contributor

@edoakes edoakes commented Aug 10, 2023

Why are these changes needed?

Fixes an issue where the _ray_trace_ctx kwarg isn't injected to the function signature if ray.init is called w/ a tracing hook after defining the function (see issue for repro).

The issue was we were checking _is_tracing_enabled at function definition time and selectively injecting the kwarg, but this variable isn't set until ray.init is called. I modified it to always inject the kwarg (matching the existing behavior for actor methods).

I've updated the tests to not explicitly call ray.init before defining the task.

Related issue number

Closes #26019

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
@edoakes edoakes changed the title [WIP] Attempt to fix tracing issue [tracing] Fix issue where actor/task is defined before ray.init is called Aug 15, 2023
@@ -163,6 +163,7 @@ def remote(self, *args, **kwargs):

return FuncWrapper()

@wrap_auto_init
Copy link
Contributor Author

Choose a reason for hiding this comment

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

auto-init needs to happen before the tracing decorator runs because it calls get_runtime_context

Comment on lines -328 to -329
if not _is_tracing_enabled():
return function
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main change: if ray.init hasn't been called then _is_tracing_enabled isn't set properly yet.

Need to always inject this kwarg optimistically. This shouldn't affect anything unless users have a kwarg called _ray_trace_ctx in their function.

Note that this is already how it worked for actor methods.

@edoakes edoakes requested review from jjyao and rkooo567 August 15, 2023 19:45
Copy link
Contributor

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

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

do we need an unit test, or is it already covered?

@edoakes
Copy link
Contributor Author

edoakes commented Aug 16, 2023

@rkooo567 it's covered by removing the ray.init in the fixture in the tests

@edoakes edoakes merged commit d52282e into ray-project:master Aug 16, 2023
92 of 98 checks passed
harborn pushed a commit to harborn/ray that referenced this pull request Aug 17, 2023
…called (ray-project#38323)

Fixes an issue where the `_ray_trace_ctx` kwarg isn't injected to the function signature if `ray.init` is called w/ a tracing hook _after_ defining the function (see issue for repro).

The issue was we were checking `_is_tracing_enabled` at function definition time and selectively injecting the kwarg, but this variable isn't set until `ray.init` is called. I modified it to always inject the kwarg (matching the existing behavior for actor methods).

I've updated the tests to not explicitly call `ray.init` before defining the task.

Signed-off-by: harborn <gangsheng.wu@intel.com>
harborn pushed a commit to harborn/ray that referenced this pull request Aug 17, 2023
…called (ray-project#38323)

Fixes an issue where the `_ray_trace_ctx` kwarg isn't injected to the function signature if `ray.init` is called w/ a tracing hook _after_ defining the function (see issue for repro).

The issue was we were checking `_is_tracing_enabled` at function definition time and selectively injecting the kwarg, but this variable isn't set until `ray.init` is called. I modified it to always inject the kwarg (matching the existing behavior for actor methods).

I've updated the tests to not explicitly call `ray.init` before defining the task.
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…called (ray-project#38323)

Fixes an issue where the `_ray_trace_ctx` kwarg isn't injected to the function signature if `ray.init` is called w/ a tracing hook _after_ defining the function (see issue for repro).

The issue was we were checking `_is_tracing_enabled` at function definition time and selectively injecting the kwarg, but this variable isn't set until `ray.init` is called. I modified it to always inject the kwarg (matching the existing behavior for actor methods).

I've updated the tests to not explicitly call `ray.init` before defining the task.

Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
rkooo567 pushed a commit that referenced this pull request Sep 8, 2023
#39362)

The single_client_tasks_and_get_batch benchmark saw a ~0.5-1k tasks/s average regression (2k tasks/s on a local machine) due to #38323, which changed some tracing logic to unconditionally change the signature of every remote function to accomodate tracing during _inject_tracing_into_function.

Make the signature change conditional again, but move it to the execution portion of RemoteFunction rather than the definition. Also make sure the injection only happens once even when the remote function is executed multiple times.
vitsai added a commit to vitsai/ray that referenced this pull request Sep 8, 2023
ray-project#39362)

The single_client_tasks_and_get_batch benchmark saw a ~0.5-1k tasks/s average regression (2k tasks/s on a local machine) due to ray-project#38323, which changed some tracing logic to unconditionally change the signature of every remote function to accomodate tracing during _inject_tracing_into_function.

Make the signature change conditional again, but move it to the execution portion of RemoteFunction rather than the definition. Also make sure the injection only happens once even when the remote function is executed multiple times.
GeneDer pushed a commit that referenced this pull request Sep 8, 2023
#39362) (#39429)

The single_client_tasks_and_get_batch benchmark saw a ~0.5-1k tasks/s average regression (2k tasks/s on a local machine) due to #38323, which changed some tracing logic to unconditionally change the signature of every remote function to accomodate tracing during _inject_tracing_into_function.

Make the signature change conditional again, but move it to the execution portion of RemoteFunction rather than the definition. Also make sure the injection only happens once even when the remote function is executed multiple times.
jimthompson5802 pushed a commit to jimthompson5802/ray that referenced this pull request Sep 12, 2023
ray-project#39362)

The single_client_tasks_and_get_batch benchmark saw a ~0.5-1k tasks/s average regression (2k tasks/s on a local machine) due to ray-project#38323, which changed some tracing logic to unconditionally change the signature of every remote function to accomodate tracing during _inject_tracing_into_function.

Make the signature change conditional again, but move it to the execution portion of RemoteFunction rather than the definition. Also make sure the injection only happens once even when the remote function is executed multiple times.

Signed-off-by: Jim Thompson <jimthompson5802@gmail.com>
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
…called (ray-project#38323)

Fixes an issue where the `_ray_trace_ctx` kwarg isn't injected to the function signature if `ray.init` is called w/ a tracing hook _after_ defining the function (see issue for repro).

The issue was we were checking `_is_tracing_enabled` at function definition time and selectively injecting the kwarg, but this variable isn't set until `ray.init` is called. I modified it to always inject the kwarg (matching the existing behavior for actor methods).

I've updated the tests to not explicitly call `ray.init` before defining the task.

Signed-off-by: Victor <vctr.y.m@example.com>
vymao pushed a commit to vymao/ray that referenced this pull request Oct 11, 2023
ray-project#39362)

The single_client_tasks_and_get_batch benchmark saw a ~0.5-1k tasks/s average regression (2k tasks/s on a local machine) due to ray-project#38323, which changed some tracing logic to unconditionally change the signature of every remote function to accomodate tracing during _inject_tracing_into_function.

Make the signature change conditional again, but move it to the execution portion of RemoteFunction rather than the definition. Also make sure the injection only happens once even when the remote function is executed multiple times.

Signed-off-by: Victor <vctr.y.m@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants