@@ -63,8 +63,9 @@ class VarLenTensor(Tensor):
6363 stride: The stride of the tensor.
6464 storage_offset: The offset into the logical ``offset`` storage.
6565 max_length: Upper bound on the length of every stored entry, or
66- :obj:`None` if unknown. Lets compiled operations size buffers
66+ :obj:`None` if unknown. Lets eager operations size buffers
6767 without reading lengths from the device. Must not underestimate.
68+ Compiled tensor operations see :obj:`None` and never recompile.
6869 """
6970
7071 ALLOWED_DTYPES : ClassVar [tuple [torch .dtype , ...] | None ] = None
@@ -576,7 +577,9 @@ def __tensor_flatten__(self) -> tuple[list[str], tuple[Any, ...]]:
576577 attrs = ["_offset" , "_data" , "_layout" ]
577578 if self ._valid is not None :
578579 attrs .append ("_valid" )
579- return attrs , (self .__class__ , self .storage_offset (), self ._max_length )
580+ # The length bound stays eager: compiled operations see ``None``.
581+ # As context, each new query bound would compile another graph.
582+ return attrs , (self .__class__ , self .storage_offset ())
580583
581584 @staticmethod
582585 def __tensor_unflatten__ (
@@ -585,7 +588,7 @@ def __tensor_unflatten__(
585588 outer_size : tuple [int , ...],
586589 outer_stride : tuple [int , ...],
587590 ) -> VarLenTensor :
588- cls , storage_offset , max_length = ctx
591+ cls , storage_offset = ctx
589592 layout = inner_tensors ["_layout" ]
590593 out = cls (
591594 data = inner_tensors ["_data" ],
@@ -594,7 +597,6 @@ def __tensor_unflatten__(
594597 size = layout .size ()[:- 1 ],
595598 stride = layout .stride ()[:- 1 ],
596599 storage_offset = storage_offset ,
597- max_length = max_length ,
598600 )
599601 out ._layout = layout
600602 return out
0 commit comments