Skip to content

Commit 62a736c

Browse files
authored
Remove line numbers from expected files (#1061)
1 parent 0c49062 commit 62a736c

File tree

3 files changed

+396
-392
lines changed

3 files changed

+396
-392
lines changed

helion/_testing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,11 @@ def replacer(match: re.Match[str]) -> str:
829829
newline = match.group("newline")
830830
return f"{indent}# src[{prefix}{suffix}]: {text}{newline}"
831831

832-
return pattern.sub(replacer, code)
832+
# Normalize structured src comments
833+
code = pattern.sub(replacer, code)
834+
835+
# Normalize file line refs: foo.py:123 -> foo.py:N
836+
return re.sub(r"(\b[^:\s]+\.py):(\d+)\b", r"\1:N", code)
833837

834838
@classmethod
835839
def normalize_code(cls, code: str) -> str:

test/test_reductions.expected

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,18 @@ def layer_norm_fwd_nonpow2(x: torch.Tensor, weight: torch.Tensor, bias: torch.Te
515515
--- assertExpectedJournal(TestReductions.test_mean)
516516
def reduce_kernel(x: torch.Tensor, fn: Callable[[torch.Tensor], torch.Tensor], out_dtype=torch.float32):
517517
n, _m =
518-
# Call: SequenceType((LiteralType(512), LiteralType(512))) SourceOrigin(location=<SourceLocation test_reductions.py:51>)
518+
# Call: SequenceType((LiteralType(512), LiteralType(512))) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
519519
# Attribute: TensorAttributeType AttributeOrigin(value=ArgumentOrigin(name='x'), key='size')
520520
# Name: TensorType([512, 512], torch.float32) ArgumentOrigin(name='x')
521521
x.size()
522522
out =
523-
# Call: TensorType([512], torch.float32) SourceOrigin(location=<SourceLocation test_reductions.py:52>)
523+
# Call: TensorType([512], torch.float32) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
524524
# Attribute: CallableType(_VariableFunctionsClass.empty) AttributeOrigin(value=GlobalOrigin(name='torch'), key='empty')
525525
# Name: PythonModuleType(torch) GlobalOrigin(name='torch')
526526
torch.empty(
527-
# List: SequenceType([LiteralType(512)]) SourceOrigin(location=<SourceLocation test_reductions.py:53>)
527+
# List: SequenceType([LiteralType(512)]) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
528528
[
529-
# Name: LiteralType(512) GetItemOrigin(value=SourceOrigin(location=<SourceLocation test_reductions.py:51>), key=0)
529+
# Name: LiteralType(512) GetItemOrigin(value=SourceOrigin(location=<SourceLocation test_reductions.py:N>), key=0)
530530
n], dtype=
531531
# Name: LiteralType(torch.float32) ArgumentOrigin(name='out_dtype')
532532
out_dtype, device=
@@ -536,38 +536,38 @@ x.device)
536536
# For: loop_type=GRID
537537

538538
for tile_n in
539-
# Call: IterType(TileIndexType(0)) SourceOrigin(location=<SourceLocation test_reductions.py:57>)
539+
# Call: IterType(TileIndexType(0)) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
540540
# Attribute: CallableType(tile) AttributeOrigin(value=GlobalOrigin(name='hl'), key='tile')
541541
# Name: PythonModuleType(helion.language) GlobalOrigin(name='hl')
542542
hl.tile(
543-
# Name: LiteralType(512) GetItemOrigin(value=SourceOrigin(location=<SourceLocation test_reductions.py:51>), key=0)
543+
# Name: LiteralType(512) GetItemOrigin(value=SourceOrigin(location=<SourceLocation test_reductions.py:N>), key=0)
544544
n):
545545

546-
# Subscript: TensorType([block_size_0], torch.float32) DeviceOrigin(location=<SourceLocation test_reductions.py:58>)
547-
# Name: TensorType([512], torch.float32) SourceOrigin(location=<SourceLocation test_reductions.py:52>)
546+
# Subscript: TensorType([block_size_0], torch.float32) DeviceOrigin(location=<SourceLocation test_reductions.py:N>)
547+
# Name: TensorType([512], torch.float32) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
548548
out[
549-
# Name: TileIndexType(0) SourceOrigin(location=<SourceLocation test_reductions.py:57>)
549+
# Name: TileIndexType(0) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
550550
tile_n] =
551-
# Call: TensorType([block_size_0], torch.float32) DeviceOrigin(location=<SourceLocation test_reductions.py:58>)
551+
# Call: TensorType([block_size_0], torch.float32) DeviceOrigin(location=<SourceLocation test_reductions.py:N>)
552552
# Name: CallableType(_VariableFunctionsClass.mean) ArgumentOrigin(name='fn')
553553
fn(
554-
# Subscript: TensorType([block_size_0, rdim_1], torch.float32) DeviceOrigin(location=<SourceLocation test_reductions.py:58>)
554+
# Subscript: TensorType([block_size_0, rdim_1], torch.float32) DeviceOrigin(location=<SourceLocation test_reductions.py:N>)
555555
# Name: TensorType([512, 512], torch.float32) ArgumentOrigin(name='x')
556556
x[
557-
# Name: TileIndexType(0) SourceOrigin(location=<SourceLocation test_reductions.py:57>)
557+
# Name: TileIndexType(0) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
558558
tile_n,
559-
# Slice: SliceType(LiteralType(None):LiteralType(None):LiteralType(None)) DeviceOrigin(location=<SourceLocation test_reductions.py:58>)
559+
# Slice: SliceType(LiteralType(None):LiteralType(None):LiteralType(None)) DeviceOrigin(location=<SourceLocation test_reductions.py:N>)
560560
:], dim=
561-
# UnaryOp: LiteralType(-1) DeviceOrigin(location=<SourceLocation test_reductions.py:58>)
561+
# UnaryOp: LiteralType(-1) DeviceOrigin(location=<SourceLocation test_reductions.py:N>)
562562
-
563-
# Constant: LiteralType(1) DeviceOrigin(location=<SourceLocation test_reductions.py:58>)
563+
# Constant: LiteralType(1) DeviceOrigin(location=<SourceLocation test_reductions.py:N>)
564564
1)
565565
return
566-
# Name: TensorType([512], torch.float32) SourceOrigin(location=<SourceLocation test_reductions.py:52>)
566+
# Name: TensorType([512], torch.float32) SourceOrigin(location=<SourceLocation test_reductions.py:N>)
567567
out
568568

569569
def root_graph_0():
570-
# File: .../test_reductions.py:58 in reduce_kernel, code: out[tile_n] = fn(x[tile_n, :], dim=-1)
570+
# File: .../test_reductions.py:N in reduce_kernel, code: out[tile_n] = fn(x[tile_n, :], dim=-1)
571571
x: "f32[512, 512]" = helion_language__tracing_ops__host_tensor('x')
572572
block_size_0: "Sym(u0)" = helion_language__tracing_ops__get_symnode('block_size_0')
573573
load: "f32[u0, u1]" = helion_language_memory_ops_load(x, [block_size_0, slice(None, None, None)], None, None); x = None
@@ -578,15 +578,15 @@ def root_graph_0():
578578
return None
579579

580580
def reduction_loop_1():
581-
# File: .../test_reductions.py:58 in reduce_kernel, code: out[tile_n] = fn(x[tile_n, :], dim=-1)
581+
# File: .../test_reductions.py:N in reduce_kernel, code: out[tile_n] = fn(x[tile_n, :], dim=-1)
582582
x: "f32[512, 512]" = helion_language__tracing_ops__host_tensor('x')
583583
block_size_0: "Sym(u0)" = helion_language__tracing_ops__get_symnode('block_size_0')
584584
load: "f32[u0, u1]" = helion_language_memory_ops_load(x, [block_size_0, slice(None, None, None)], None, None); x = block_size_0 = None
585585
mean_extra: "f32[u0]" = helion_language__tracing_ops__inductor_lowering_extra([load]); load = None
586586
return [mean_extra]
587587

588588
def root_graph_2():
589-
# File: .../test_reductions.py:58 in reduce_kernel, code: out[tile_n] = fn(x[tile_n, :], dim=-1)
589+
# File: .../test_reductions.py:N in reduce_kernel, code: out[tile_n] = fn(x[tile_n, :], dim=-1)
590590
block_size_0: "Sym(u0)" = helion_language__tracing_ops__get_symnode('block_size_0')
591591
_get_symnode = helion_language__tracing_ops__get_symnode('rdim1')
592592
_for_loop = helion_language__tracing_ops__for_loop(1, [0], [_get_symnode], []); _get_symnode = None

0 commit comments

Comments
 (0)