Skip to content

Commit a86a975

Browse files
committed
Add logs for helping debug address space overflow issue
1 parent 9fafdb0 commit a86a975

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

exir/emit/_emitter.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
TensorShapeDynamism,
8080
)
8181
from executorch.exir.tensor import (
82+
AddressSpaceOverflowException,
8283
layout_enum,
8384
make_allocation_info,
8485
make_tensor_value,
@@ -349,7 +350,20 @@ def _tensor_spec_to_evalue(self, spec: TensorSpec) -> EValue:
349350
self.node,
350351
f"Non-const tensor should be an activation tensor: mem_offset {spec.mem_offset}",
351352
)
352-
allocation_info = make_allocation_info(spec.mem_id, spec.mem_offset)
353+
try:
354+
allocation_info = make_allocation_info(spec.mem_id, spec.mem_offset)
355+
except AddressSpaceOverflowException as e:
356+
raise InternalError(
357+
self._emit_node_specific_error(
358+
self.node,
359+
(
360+
f"{e}\nHint: If you are using a memory pass based on dynamic shape bounds, "
361+
f"such as ConstraintBasedSymShapeEvalPass, this may be the cause of an "
362+
f"unbacked SymInt with its upper bound lazily set to 2^64-1 (uint64 max) "
363+
"during torch.export()."
364+
)
365+
)
366+
)
353367

354368
if spec.const:
355369
# Tensor with a blob we need to serialize. May not actually be constant at runtime

exir/passes/sym_shape_eval_pass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class HintBasedSymShapeEvalPass(PassBase):
181181
182182
Warning: if you're using torch.export with constrain API, this method doesn't respect the input constraints.
183183
184-
Not inherit from ExportPass since we simply need a way to iterate thru
184+
Not inherited from ExportPass since we simply need a way to iterate thru
185185
every node's output. PassBase is easier for that purpose.
186186
"""
187187

@@ -245,7 +245,7 @@ class ConstraintBasedSymShapeEvalPass(PassBase):
245245
formula. We should convert those symbolic formula to concrete value for
246246
static/upperbound tensors so we can properly do memory planning for them.
247247
248-
Not inherit from ExportPass since we simply need a way to iterate thru
248+
Not inherited from ExportPass since we simply need a way to iterate through
249249
every node's output. PassBase is easier for that purpose.
250250
"""
251251

exir/tensor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
from executorch.exir.schema import ScalarType, TensorShapeDynamism
2222
from executorch.exir.sym_util import eval_shape
2323

24+
class AddressSpaceOverflowException(Exception):
25+
pass
26+
2427

2528
def num_bytes_from_shape_and_dtype(shape: torch.Size, dtype: torch.dtype) -> int:
2629
"""
@@ -297,7 +300,7 @@ def make_allocation_info(mem_id: int, mem_offset: int) -> schema.AllocationDetai
297300
memory_offset_low = mem_offset & ((1 << 32) - 1)
298301
memory_offset_high = mem_offset >> 32
299302
if memory_offset_high >= 1 << 32:
300-
raise ValueError(f"mem_offset {mem_offset} does not fit in 64 bits")
303+
raise AddressSpaceOverflowException(f"mem_offset {mem_offset} does not fit in 64 bits")
301304

302305
allocation_info = schema.AllocationDetails(
303306
memory_id=mem_id,

0 commit comments

Comments
 (0)