-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[core] Split raylet cython file into multiple files (DynamicObjectRefGenerator) #52095
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
[core] Split raylet cython file into multiple files (DynamicObjectRefGenerator) #52095
Conversation
-e Signed-off-by: machichima <[email protected]>
…cython-dynamic-obj-ref-gen -e Signed-off-by: machichima <[email protected]>
Hi @dentiny , I'm new to cython and might make some mistake here. Please have a look and let me know if anything should be modified. Thanks! |
I think you need to change all python caller side? |
It seems like the import error happens in [2025-04-08T15:10:13Z] Traceback (most recent call last):
[2025-04-08T15:10:13Z] File "/root/.cache/bazel/_bazel_root/1df605deb6d24fc8068f6e25793ec703/execroot/com_github_ray_project_ray/bazel-out/k8-opt/bin/python/ray/autoscaler/v2/tests/test_sdk.runfiles/com_github_ray_project_ray/python/ray/autoscaler/v2/tests/test_sdk.py", line 11, in <module>
[2025-04-08T15:10:13Z] import ray
[2025-04-08T15:10:13Z] File "/rayci/python/ray/__init__.py", line 85, in <module>
[2025-04-08T15:10:13Z] import ray._raylet # noqa: E402
[2025-04-08T15:10:13Z] File "python/ray/_raylet.pyx", line 1, in init ray._raylet
[2025-04-08T15:10:13Z] ModuleNotFoundError: No module named 'ray.cython_components.object_ref_generator' |
-e Signed-off-by: machichima <[email protected]>
…cython-dynamic-obj-ref-gen -e Signed-off-by: machichima <[email protected]>
-e Signed-off-by: machichima <[email protected]>
-e Signed-off-by: machichima <[email protected]>
-e Signed-off-by: machichima <[email protected]>
-e Signed-off-by: machichima <[email protected]>
Hi @dentiny , Thanks! |
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're two main purpose for the issue (split classes and functions out of the giant cython file as possible):
- (major) speed up compilation speed, it's a painpoint for any dev work related to FFI
- (minor) increase code maintainability by moving some pieces out of the file (you could tell the file is so large)
I think your change fits in the second purpose, so it looks ok to me.
CC @jjyao / @edoakes / @dayshah if you have other thoughts.
@@ -0,0 +1,17 @@ | |||
from ray.util.annotations import DeveloperAPI |
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.
this is not cython code so there's no need to put it under cython_components
. how about just ray/_private/dynamic_object_ref_generator.py
?
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.
Sure! Just moved it to _private.
Thanks!
-e Signed-off-by: machichima <[email protected]>
def __init__(self, refs): | ||
# TODO(swang): As an optimization, can also store the generator | ||
# ObjectID so that we don't need to keep individual ref counts for the | ||
# inner ObjectRefs. | ||
self._refs = refs | ||
|
||
def __iter__(self): | ||
for ref in self._refs: | ||
yield ref | ||
|
||
def __len__(self): | ||
return len(self._refs) |
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.
while you're at it, do you mind adding type hints for this code?
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.
Will do!
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.
Hi @edoakes ,
I just tried and notice that we cannot import ObjectRef
here, as this is the .py
file, and from ray import ObjectRef
cause the circular import. Would you mind if I use list[Any]
here for refs
? Or is there any way that I can use ObjectRef
as type here?
Thanks!
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.
I think you can use a string type hint instead: List["ray.ObjectRef"]
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.
@edoakes I just added the type hint. PTAL
Thanks!
…cython-dynamic-obj-ref-gen -e Signed-off-by: machichima <[email protected]>
…cython-dynamic-obj-ref-gen -e Signed-off-by: machichima <[email protected]>
…cython-dynamic-obj-ref-gen -e Signed-off-by: machichima <[email protected]>
-e Signed-off-by: machichima <[email protected]>
98a3c5f
to
d894486
Compare
-e Signed-off-by: machichima <[email protected]>
thanks @machichima ! |
…Generator) (ray-project#52095) As mentioned in ray-project#51080, separate `DynamicObjectRefGenerator` class from the large `_raylet.pyx` file. Closes ray-project#52029
Sorry for leaving comment in a merged PR. This could be just a minor change.. while self._refs:
yield self._refs.pop(0) I am asking this because the len/size changes after each iteration/next() in the old behavior, while it keeps the full list and keeps the len in the new behavior. |
cc @edoakes not that familiar with how DynamicObjectRefGenerator works, but any concern of the object sticking around longer in obj store bc the ref sticks around in the list without the pop? |
…Generator) (ray-project#52095) As mentioned in ray-project#51080, separate `DynamicObjectRefGenerator` class from the large `_raylet.pyx` file. Closes ray-project#52029
@wingkitlee0 I confirmed this did introduce an actual bug and opened a pr to fix it. Thanks a lot for noticing it and bringing it up and being a great member of the Ray community! |
In #52095, the while loop in DynamicObjectRefGenerator that pops the ref was just changed to a for loop that iterates through the refs. This results in the refs sticking around and using up memory when they can be destroyed. Also changing the list to a deque for efficiency on popping from the front. --------- Signed-off-by: dayshah <[email protected]>
…Generator) (ray-project#52095) As mentioned in ray-project#51080, separate `DynamicObjectRefGenerator` class from the large `_raylet.pyx` file. Closes ray-project#52029 Signed-off-by: zhaoch23 <[email protected]>
In ray-project#52095, the while loop in DynamicObjectRefGenerator that pops the ref was just changed to a for loop that iterates through the refs. This results in the refs sticking around and using up memory when they can be destroyed. Also changing the list to a deque for efficiency on popping from the front. --------- Signed-off-by: dayshah <[email protected]> Signed-off-by: zhaoch23 <[email protected]>
In ray-project#52095, the while loop in DynamicObjectRefGenerator that pops the ref was just changed to a for loop that iterates through the refs. This results in the refs sticking around and using up memory when they can be destroyed. Also changing the list to a deque for efficiency on popping from the front. --------- Signed-off-by: dayshah <[email protected]> Signed-off-by: Vicky Tsang <[email protected]>
Why are these changes needed?
As mentioned in #51080, separate
DynamicObjectRefGenerator
class from the large_raylet.pyx
file.Related issue number
Closes #52029
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.