-
-
Notifications
You must be signed in to change notification settings - Fork 644
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
[Feature Request] Support for Var Args and Positional Only Args #1432
Comments
Hi @monney. I am open to an attempt to add this, but as I said in the other feature request the surface area of instantiate is very large. A few things to consider:
# example passing 1,2,3 as positional to the first node, and 4,5,6 to the nested one.
instantiate(cfg.node, {"_args_": [1,2,3], foo={"_args_" : [4,5,6]}})
As you can see, there is a lot going on here. Regarding support for instantiating tuples and sets: This is supported, but not with recursive instantiation. In [17]: utils.instantiate({"_target_" : "builtins.tuple"}, [1,2,3])
Out[17]: (1, 2, 3)
In [18]: utils.instantiate({"_target_" : "builtins.set"}, [1,2,3])
Out[18]: {1, 2, 3} |
Will take a look at it for 1.2. It may get into 1.1 if you can deliver a solution before it gets released. |
I agree with the 1.2 timeline, given the complexity, it will take me some time. A, few questions, currently the tuple instantiation and "args" doesn't work through yaml properties, correct? Only through passing it in the instantiate function? Could you clarify what you mean by passthrough to nested nodes? Thanks |
instantiation of builtins works.
You mean "There should be a way to pass positional arguments as passthrough to nested config nodes" ? This if we use # example passing 1,2,3 as positional to the first node, and 4,5,6 to the nested one.
instantiate(cfg.node, {"_args_": [1,2,3], foo={"_args_" : [4,5,6]}}) |
For builtins I can't get tuple at least to work with yaml only, since 3.8 because it requires positional only. For passthrough I had never tried that, I'll keep that in mind for implementation and tests. I'll start going over the new instantiate code to get a gauge on things. |
I have a pretty big PR changing instantiation that I am going to merge soon. see the outstanding pull requests. |
🚀 Feature Request
Hi Omry!
In a yaml file under the
_target_
I'd like the ability to pass things to functions and constructors which accept var args or positional only arguments.Motivation
Is your feature request related to a problem? Please describe.
Functions like
np.random.randn
are currently uncallable. Some Objects are unconstructable.Pitch
Describe the solution you'd like
I'd like to be able to write something like this in a yaml file
for var args the syntax might be something like this:
Describe alternatives you've considered
_args_
instead ofargs
.kwargs
, and pass by position by default.Are you willing to open a pull request? (See CONTRIBUTING)
Yes
Additional context
I've tried on master (1.1.dev5)
As a side note, this feature is necessary to support instantiation of tuples and sets, but that is a separate feature request I'll likely make once if this becomes supported.
The text was updated successfully, but these errors were encountered: