-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Support calling positional arguments by keyword (fix #998) #2081
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
Conversation
I also note that funcsigs has a function Signature.bind that does exactly what extend_args is built to do, and should handle all the weird edge cases for us. I didn't make this change as there is some Cython-related magic going on in get_signature_params that I think might break this. Could someone who understands the related code better comment? |
Thanks @AdamGleave, this looks really great! I think you're right that we need to switch to having Could you quickly run something like import ray
import cProfile
ray.init()
@ray.remote
def f(a, b, c, x=1, y=2, z=3):
pass
ray.get(f.remote(1, 2, 3))
cProfile.run('for _ in range(10000): f.remote(1, 2, 3)') before and after this change and see if the amount of time spent in @danielsuo implemented support for Cython in #1193. |
Test PASSed. |
Thanks for the profiling code @robertnishihara . The changes don't seem to have had much impact on performance -- it's hovering around 130ms spent in extend_args with or without changes. For completeness, I tested it on a 6-core i7-3930K, and the full results are below. I tried running it several times (not reported) but the results were pretty consistent from run to run.
|
Ok, sounds good. I'm seeing the following test failure from
Looks like that test needs to be updated. Also, can you run
and commit the resulting change to that file? We have some fairly strict linting checks. |
I've updated signature.py to conform to code style. yapf made some awkward line breaks so I manually split out some of the deeply nested booleans to make the structure clearer. Apologies for not catching that failing test. I think Ray should accept functions of that form ( |
Ok thanks! Yeah, we should support functions of that form. The only reason for the test was that they didn't work before this PR I think. |
Test PASSed. |
I had to push a small change, I think our versions of yapf may differ. Anyway, will merge soon. Thanks again! |
Test PASSed. |
Thanks again, this is a huge help! |
* master: (22 commits) [xray] Fix bug in updating actor execution dependencies (ray-project#2064) [DataFrame] Refactor __delitem__ (ray-project#2080) [xray] Better error messaging when pulling from self. (ray-project#2068) Use source code in hash where possible (fix ray-project#2089) (ray-project#2090) Functions for flushing done tasks and evicted objects. (ray-project#2033) Fix compilation error for RAY_USE_NEW_GCS with latest clang. (ray-project#2086) [xray] Corrects Error Handling During Push and Pull. (ray-project#2059) [xray] Sophisticated task dependency management (ray-project#2035) Support calling positional arguments by keyword (fix ray-project#998) (ray-project#2081) [DataFrame] Improve performance of iteration methods (ray-project#2026) [DataFrame] Implement to_csv (ray-project#2014) [xray] Lineage cache only requests notifications about remote parent tasks (ray-project#2066) [rllib] Add magic methods for rollouts (ray-project#2024) [DataFrame] Allows DataFrame constructor to take in another DataFrame (ray-project#2072) Pin Pandas version for Travis to 0.22 (ray-project#2075) Fix python linting (ray-project#2076) [xray] Fix GCS table prefixes (ray-project#2065) Some tests for _submit API. (ray-project#2062) [rllib] Queue lib for python 2.7 (ray-project#2057) [autoscaler] Remove faulty assert that breaks during downscaling, pull configs from env (ray-project#2006) ...
* master: (24 commits) Performance fix (ray-project#2110) Use flake8-comprehensions (ray-project#1976) Improve error message printing and suppression. (ray-project#2104) [rllib] [doc] Broken link in ddpg doc YAPF, take 3 (ray-project#2098) [rllib] rename async -> _async (ray-project#2097) fix unused lambda capture (ray-project#2102) [xray] Use pubsub instead of timeout for ObjectManager Pull. (ray-project#2079) [DataFrame] Update _inherit_docstrings (ray-project#2085) [JavaWorker] Changes to the build system for support java worker (ray-project#2092) [xray] Fix bug in updating actor execution dependencies (ray-project#2064) [DataFrame] Refactor __delitem__ (ray-project#2080) [xray] Better error messaging when pulling from self. (ray-project#2068) Use source code in hash where possible (fix ray-project#2089) (ray-project#2090) Functions for flushing done tasks and evicted objects. (ray-project#2033) Fix compilation error for RAY_USE_NEW_GCS with latest clang. (ray-project#2086) [xray] Corrects Error Handling During Push and Pull. (ray-project#2059) [xray] Sophisticated task dependency management (ray-project#2035) Support calling positional arguments by keyword (fix ray-project#998) (ray-project#2081) [DataFrame] Improve performance of iteration methods (ray-project#2026) ...
What do these changes do?
Python positional arguments can also be called via their keyword, with Python allowing the caller to choose between these two styles. (Exception: some built-in and C-bound functions only support positional arguments.) Ray only supported calling keyword arguments when they had a default value, a surprising semantic for Python users.
This PR adds support keyword arguments in all common cases. It also adds unit tests to verify Ray accepts the keyword arguments, and rejects invalid uses.
There are a few unusual cases it does not support (but will warn the user of):
*
or*args
. Ideally we'd support this too -- I've intentionally written code like def f(*, kwd1, kwd2) to force callers to use keyword arguments. This doesn't seem difficult conceptually, but requires changing the return type of extend_args to be args, kwargs rather than just. This impacts a number of call sites I do not understand fully, so I decided not to touch this.Related issue number
Addresses #998 (apart from the caveats described above).