-
Notifications
You must be signed in to change notification settings - Fork 43
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
Fixing support for SymInts #518
Comments
@gramalingam @xiaowuhu this would change how we represent symints and change the recommendation from using INT64 to using Sequence[INT64] |
@titaiwangms relevant for dynamic axes support, because the ConcatFromSequence node may now be the function's responsibility. |
Hmm we can’t really use SequenceConstruct because we run into the no len issue again. Maybe we need to implement len for our tensor instead? or just len for sequence construct |
~Yeah since start_axis is an attribute we cannot even represent it as List[INT64]. ~ we can because we are just using the rank and not the tensors themselves. And this is trace only (static) |
This comment was marked as resolved.
This comment was marked as resolved.
I thought about this again. Maybe what’s better is to go with Ti-tai’s solution where we programmatically handle list of tensors, and implement len on onnx script Tensors. This way the change is minimal and functions are kept simple. |
AFAIK, symbolic fx.graph generates aten::sym_size to replace real shape value of size. For example, size input in op.Expand is like [2, 3, 4] when the shape is fixed, but with symbolic graph, we will have [sym_size0, sym_size1, sym_size2], and each of them connecting to fx.Node. What the PR have now is to check if the value is List[INT64] or not, to decide it goes to op.Concat or op.Constant. Current status is that It goes great with most of dynamic cases we had in addhoc, but breaks test_fx static shape cases with some input out of bounds problems which I am still looking into. Most likely, it's the differences between symbolic fx.graph and fake fx.graph causing the regression. We can have more discussion on Monday to sync up on this topic! related issue: #481 |
I think I kind of understand the concern here now. Yes, and I think stick with List[INT64] would make the code in converter side more clear as well. |
In the atenlib office hour, we decided that: 1. We use INT64 to represent sequence of symints. 2. Concat should be done by the exporter. |
Used by pytorch/pytorch#96350 fixes #518 fixes #390 --------- Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
In PyTorch, SymInts or symbolic ints is a way of supporting dynamic attributes. In atenlib we tend to represent them as
INT64
tensors to maintain their dynamic nature. However in fx, they are usually passed in as a list of nodes (a list of tensors).It may be better if we use
Sequence[INT64]
to represent them to maintain consistency with the fx graph.This representation further enables
trace_only
support for SymInts when we need to obtain a rank. (#517)As an example in the
native_layer_norm
:Here
normalized_shape
is a SymInt sequence. If we annotate it asSequence[int]
, it will be considered an attribute by onnxscript and fail with a TypeError because we rejectTorchScriptTensor
types as attributes; if we annotate it asINT64
, the Python line for taking the rankstart_axis = -len(normalized_shape)
will fail becauseTorchScriptTensor
does not havelen
defined, and we cannot useop.Neg(op.Size(op.Shape(normalized_shape)))
becausestart_axis
is subsequently used as an attribute (so not dynamic) inLayerNormalization
.Change required
For this change, we need to update how we convert python scalar inputs to tensors: Whereas before we convert
List[int]
toINT64
, we should now convert them toList[INT64]
tensors (convert each element to INT64 thenSequenceConstruct
). Functions that take SymInts should useConcatFromSequence
to concatenate the sequence into a single tensor for its own use.Potential issues
SymInt
sequences are passed as lists? Can the length (aka. rank) be dynamic too which will force us to useINT64
, or useINT64
->SplitToSequence
?ConcatFromSequence
.cc @titaiwangms @BowenBao @xiaowuhu @fatcat-z @gramalingam
The text was updated successfully, but these errors were encountered: