@@ -29,17 +29,22 @@ class _GridSamplerStorageWorkaround:
2929 # Temporary upstream workaround:
3030 # `nemotron_ocr_cpp.indirect_grid_sample_forward(...)` intermittently
3131 # raises "Tensor doesn't have storage" for tensors that appear valid from
32- # Python. Force fresh owned contiguous storage at the wrapper boundary .
32+ # Python. Retry the failed call once with fresh owned contiguous tensors .
3333 def __init__ (self , original_sampler : Any ):
3434 self ._original_sampler = original_sampler
3535
3636 def __call__ (self , input_tensor : Any , grid : Any , input_indices : Any ) -> Any :
3737 # Workaround call site for the upstream custom-op storage bug.
38- return self ._original_sampler (
39- input_tensor .contiguous ().clone (),
40- grid .contiguous ().clone (),
41- input_indices .contiguous ().clone (),
42- )
38+ try :
39+ return self ._original_sampler (input_tensor , grid , input_indices )
40+ except RuntimeError as exc :
41+ if "doesn't have storage" not in str (exc ):
42+ raise
43+ return self ._original_sampler (
44+ input_tensor .contiguous ().clone (),
45+ grid .contiguous ().clone (),
46+ input_indices .contiguous ().clone (),
47+ )
4348
4449
4550class NemotronOcrPrediction (TypedDict ):
0 commit comments