-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[jit] Add default values in script #11962
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
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
}; | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Helper nodes (mostly for function arguments) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
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.
Adding support for default arguments is a great thing to work on, but I think this is ultimately not the right approach. Instead, I would suggest a much simpler set of changes:
- Extract the default values from the original functions using: https://stackoverflow.com/questions/12627118/get-a-function-arguments-default-value
- Compile the function into a graph as is, without changing the compiler or
ir.h
, deriving ascript::Method
object without any default values in it. Use the types inside of the derivedFunctionSchema
object andinline IValue toIValue(py::handle obj, const TypePtr& type)
to turn the python default value into an IValue. - Generate a new
FunctionSchema
object that includes the default IValues, and callsetSchema
on the Method to install it.
This approach is more modular (it doesn't require changes to AST parsing, the compiler, or the IR), and it relies on components we already have to robustly convert python values into IValue objects.
struct Value { | ||
TH_DISALLOW_COPY_AND_ASSIGN(Value); | ||
Value(Node * node_, size_t offset_); | ||
virtual ~Value() {} |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
at::optional<IValue> default_value = at::nullopt; | ||
if (decl_arg.has_default()) { | ||
// If the Param has a default value, convert it to an IValue | ||
Const default_const = decl_arg.default_value(); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
PR adds support for
int
andfloat
default values for script functions (values get cast toTensor
implicitly). Resolves expressions viaeval
(but only for types that can convert to aTensor
)@apaszke @zdevito @ezyang