Skip to content

Conversation

@justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Jan 25, 2023

Create param_manipulation for separate inputs and attributes from python args and kwargs.
Raname typing.py to onnxscript/function_libs/torch_aten/tensor_typing.py

@justinchuby justinchuby marked this pull request as ready for review January 26, 2023 00:22
@justinchuby justinchuby changed the title feat(eager): separate inputs from attributes feat(atenlib): separate inputs from attributes Jan 26, 2023
@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #368 (22e9b84) into main (2b84597) will decrease coverage by 0.17%.
The diff coverage is 61.86%.

@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
- Coverage   73.66%   73.50%   -0.17%     
==========================================
  Files          97       99       +2     
  Lines        9710     9821     +111     
==========================================
+ Hits         7153     7219      +66     
- Misses       2557     2602      +45     
Impacted Files Coverage Δ
...nxscript/function_libs/torch_aten/tensor_typing.py 100.00% <ø> (ø)
...ipt/function_libs/torch_aten/param_manipulation.py 46.83% <46.83%> (ø)
onnxscript/irbuilder.py 80.00% <66.66%> (-0.31%) ⬇️
...unction_libs/torch_aten/param_manipulation_test.py 96.15% <96.15%> (ø)
onnxscript/function_libs/torch_aten/ops/core.py 64.98% <100.00%> (ø)
onnxscript/function_libs/torch_aten/ops/nn.py 59.93% <100.00%> (ø)
onnxscript/function_libs/torch_aten/ops/special.py 62.41% <100.00%> (ø)
onnxscript/values.py 88.35% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@justinchuby justinchuby merged commit 3f433e7 into main Jan 26, 2023
@justinchuby justinchuby deleted the justinchu/param-manipulation branch January 26, 2023 01:56
@justinchuby justinchuby added module: torchlib Related to the torch/aten function lib in development topic: api labels Jan 26, 2023
default: Any = _EmptyDefault
is_input: bool = True

def __repr__(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the return value supposed to be valid python or just a description?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering whether str is more appropriate or repr ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks!


def __repr__(self) -> str:
param_kind = "INPUT" if self.is_input else "ATTRIBUTE"
text = f"{self.name}<{param_kind}>: {self.type}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit (optional): f"{self.name} : {param_kind}({self.type})" or f"{param_kind} {self.name} : {self.type}" would be more readable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SG!

Copy link
Collaborator Author

@justinchuby justinchuby Feb 3, 2023

Choose a reason for hiding this comment

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

a<INTPUT>: INT64

vs

INPUT a : INT64
a : INTPUT(INT64)

Copy link
Collaborator Author

@justinchuby justinchuby Feb 3, 2023

Choose a reason for hiding this comment

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

I will go with a: Input[INT64]


Attributes:
name: The name of the parameter.
type: The type of the parameter.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we have multiple type representations, which one is this supposed to be? Eg., is this supposed to be python-types (like "int" and "List[FLOAT]") ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think Python types sg. For now not really enforced and it could be anything

return not self.is_input


def extract_param_schema_from_function(onnx_func: values.OnnxFunction) -> List[ParamSchema]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The current OnnxFunction IR loses the positional-order information between inputs and attributes (since we didn't care about it then given our assumptions that all inputs come first). We can't reconstruct it subsequently.

Perhaps we should consider updating OnnxFunction IR to store a List[ParamSchema] in the first place ... just thinking out aloud, haven't read the rest of the PR yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like this idea! I was going to propose exposing ParamSchema somewhere in the function and op as the next thing to do so we have a common interface as #320

onnx_attributes[param.name] = kwargs[param.name]
else:
# input doesn't have default
onnx_attributes[param.name] = param.default
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't seen the usage of this function. Perhaps some usage contexts would not want default-values to be filled in. Anyway, I guess we can cross that bridge when we come to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a fill_defaults option to the function

justinchuby added a commit that referenced this pull request Feb 6, 2023
)

Generalize #368 to all eager backends

split happens in the evaluator instead of the Op or OnnxFunction call
methods so that evaluators can control behaviors like whether to fill in
default values for attributes.

Fixes #287, partially #305 (still need the scripted version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: torchlib Related to the torch/aten function lib in development topic: api

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants