You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm testing creating structs to represent tensor operations to be used as Modules inside model definitions, but when trying to create a Module to represent Tensor concatenation, the rust type/trait system go crazy on the trait bounds. Usually the shape of a tensor is a generic parameter that's actually a "shape", but when doing something like:
impl<A,B,Ax,E:Dtype,D,T:Tape<E,D>,R:Tape<E,D>>Module<(Tensor<A,E,D,T>,Tensor<B,E,D,R>)>forConcatTensorAlong<Ax>where(A,B):TryConcatAlong<Ax>,// <- this line is problematic// etc{typeOutput = /**/;fntry_forward(&self,x:(Tensor<A,E,D,T>,Tensor<B,E,D,R>),) -> Result<Self::Output,Error>{// etc}}
In this case, ConcatTensorAlong would be the struct representing a Module.
But when adding what was indicated by as "problematic"*, the rust type system (for some reason) insists in considering A and B to be yet other Tensors, so it tries to verify the trait bounds of Tensor<Tensor<Tensor<...>>> recursively, until it crashes.
*but only if I actually try to use ConcatTensorAlong inside a Model and call forward on it.
This is the error I get:
And well, increasing the recursion limit doesn't help. At first I didn't even read the thing, assumed that my model was too big or something, and increased the recursion to 1024 but noticed that the rust compiler itself crashed instead.
Currently I've noticed that if TryConcatAlong is separated into two different traits, one for Tensor and another for Shape, and adjusting the trait bounds accordingly around the code, rust no longer crashes for that kind of Module definition.
The text was updated successfully, but these errors were encountered:
swfsql
changed the title
Separate TryConcatAlong into different traits
Split TryConcatAlong into different traits
Nov 16, 2023
This issue is a request to separate the
TryConcatAlong
trait into two different traits, one for Tensors and another for Shapes.edit: A small example on disc.
I'm testing creating structs to represent tensor operations to be used as Modules inside model definitions, but when trying to create a Module to represent Tensor concatenation, the rust type/trait system go crazy on the trait bounds. Usually the shape of a tensor is a generic parameter that's actually a "shape", but when doing something like:
In this case,
ConcatTensorAlong
would be the struct representing a Module.But when adding what was indicated by as "problematic"*, the rust type system (for some reason) insists in considering A and B to be yet other Tensors, so it tries to verify the trait bounds of
Tensor<Tensor<Tensor<...>>>
recursively, until it crashes.*but only if I actually try to use
ConcatTensorAlong
inside a Model and callforward
on it.This is the error I get:
And well, increasing the recursion limit doesn't help. At first I didn't even read the thing, assumed that my model was too big or something, and increased the recursion to 1024 but noticed that the rust compiler itself crashed instead.
Currently I've noticed that if
TryConcatAlong
is separated into two different traits, one for Tensor and another for Shape, and adjusting the trait bounds accordingly around the code, rust no longer crashes for that kind of Module definition.The text was updated successfully, but these errors were encountered: