Skip to content

Commit 0e2a065

Browse files
justinchubyCopilot
andcommitted
Fix review findings: consistent naming, public imports, lint, docstring
- Rename graph_builder to builder in _gemma4.py and _vision_language_3model.py for consistency with other 22 task files - Change GraphBuilder import from onnxscript._internal.builder (private) to onnxscript (public API) in _base.py, _cache_utils.py, _causal_lm.py, _gemma4.py - Fix import sorting and line length issues flagged by lintrunner - Update _make_graph() docstring to mention builder.add_output() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Justin Chu <justinchu@microsoft.com>
1 parent 1e1cbe5 commit 0e2a065

24 files changed

Lines changed: 273 additions & 137 deletions

src/mobius/tasks/_adapter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ def build(
2929
# Determine input shape based on adapter type
3030
if hasattr(config, "in_channels"):
3131
# T2I-Adapter: conditioning image input
32-
condition = builder.input("condition", dtype=ir.DataType.FLOAT, shape=["batch", config.in_channels, "height", "width"])
32+
condition = builder.input(
33+
"condition",
34+
dtype=ir.DataType.FLOAT,
35+
shape=["batch", config.in_channels, "height", "width"],
36+
)
3337
else:
3438
# IP-Adapter: image embedding input
35-
condition = builder.input("image_embeds", dtype=ir.DataType.FLOAT, shape=["batch", config.image_embed_dim])
39+
condition = builder.input(
40+
"image_embeds",
41+
dtype=ir.DataType.FLOAT,
42+
shape=["batch", config.image_embed_dim],
43+
)
3644

3745
outputs = module(op, condition)
3846

src/mobius/tasks/_audio_feature_extraction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def build(
3131
graph, builder = _make_graph()
3232
op = builder.op
3333

34-
input_values = builder.input("input_values", dtype=ir.DataType.FLOAT, shape=["batch", "time"])
34+
input_values = builder.input(
35+
"input_values", dtype=ir.DataType.FLOAT, shape=["batch", "time"]
36+
)
3537

3638
last_hidden_state = module(op, input_values=input_values)
3739

src/mobius/tasks/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from typing import ClassVar
1010

1111
import onnx_ir as ir
12-
from onnxscript import nn
13-
from onnxscript._internal.builder import GraphBuilder
12+
from onnxscript import GraphBuilder, nn
1413

1514
import mobius
1615
from mobius._configs import BaseModelConfig
@@ -108,6 +107,7 @@ def _make_graph(
108107
"""Create an empty graph and its builder.
109108
110109
Inputs should be added after creation via ``builder.input()``.
110+
Outputs should be registered via ``builder.add_output()``.
111111
112112
Returns:
113113
``(graph, builder)`` — call ``builder.op`` to get the op handle.

src/mobius/tasks/_cache_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import NamedTuple
1515

1616
import onnx_ir as ir
17-
from onnxscript._internal.builder import GraphBuilder
17+
from onnxscript import GraphBuilder
1818

1919
from mobius._configs import BaseModelConfig
2020

src/mobius/tasks/_causal_lm.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from __future__ import annotations
77

88
import onnx_ir as ir
9-
from onnxscript import nn
10-
from onnxscript._internal.builder import GraphBuilder
9+
from onnxscript import GraphBuilder, nn
1110

1211
from mobius._configs import ArchitectureConfig
1312
from mobius._model_package import ModelPackage
@@ -121,7 +120,9 @@ def build(
121120
# --- Cache setup (static vs dynamic) ---
122121
if static:
123122
attention_mask = None
124-
position_ids = builder.input("position_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len])
123+
position_ids = builder.input(
124+
"position_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len]
125+
)
125126
past_key_values = _make_static_cache_inputs(
126127
builder,
127128
config.num_hidden_layers,
@@ -134,9 +135,13 @@ def build(
134135
else:
135136
past_seq_len = ir.SymbolicDim("past_sequence_len")
136137
attention_mask = builder.input(
137-
"attention_mask", dtype=ir.DataType.INT64, shape=[batch, "past_seq_len + seq_len"],
138+
"attention_mask",
139+
dtype=ir.DataType.INT64,
140+
shape=[batch, "past_seq_len + seq_len"],
141+
)
142+
position_ids = builder.input(
143+
"position_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len]
138144
)
139-
position_ids = builder.input("position_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len])
140145

141146
# MLA attention: K/V heads equal q heads (no GQA reduction in
142147
# latent space). The ONNX Attention op is called with
@@ -222,9 +227,13 @@ def build(
222227

223228
input_ids = builder.input("input_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len])
224229
attention_mask = builder.input(
225-
"attention_mask", dtype=ir.DataType.INT64, shape=[batch, "past_seq_len + seq_len"],
230+
"attention_mask",
231+
dtype=ir.DataType.INT64,
232+
shape=[batch, "past_seq_len + seq_len"],
233+
)
234+
position_ids = builder.input(
235+
"position_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len]
226236
)
227-
position_ids = builder.input("position_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len])
228237

229238
past_key_values = _make_hybrid_cache_inputs(
230239
builder,
@@ -289,10 +298,14 @@ def _make_static_cache_inputs(
289298

290299
# Shared inputs across all layers
291300
write_indices = builder.input(
292-
"write_indices", dtype=ir.DataType.INT64, shape=[batch],
301+
"write_indices",
302+
dtype=ir.DataType.INT64,
303+
shape=[batch],
293304
)
294305
nonpad_kv_seqlen = builder.input(
295-
"nonpad_kv_seqlen", dtype=ir.DataType.INT64, shape=[batch],
306+
"nonpad_kv_seqlen",
307+
dtype=ir.DataType.INT64,
308+
shape=[batch],
296309
)
297310

298311
# Build StaticCacheState for each layer (shared indices)

src/mobius/tasks/_codec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def _build_encoder(
8989
audio_len = ir.SymbolicDim("audio_length")
9090

9191
graph, builder = _make_graph(name="encoder")
92-
waveform = builder.input("waveform", dtype=ir.DataType.FLOAT, shape=[batch, 1, audio_len])
92+
waveform = builder.input(
93+
"waveform", dtype=ir.DataType.FLOAT, shape=[batch, 1, audio_len]
94+
)
9395

9496
codes = encoder(builder.op, waveform)
9597

src/mobius/tasks/_controlnet.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,22 @@ def build(
3131
graph, builder = _make_graph()
3232
op = builder.op
3333

34-
sample = builder.input("sample", dtype=ir.DataType.FLOAT, shape=["batch", config.in_channels, "height", "width"])
34+
sample = builder.input(
35+
"sample",
36+
dtype=ir.DataType.FLOAT,
37+
shape=["batch", config.in_channels, "height", "width"],
38+
)
3539
timestep = builder.input("timestep", dtype=ir.DataType.INT64, shape=["batch"])
36-
encoder_hidden_states = builder.input("encoder_hidden_states", dtype=ir.DataType.FLOAT, shape=["batch", "sequence_length", config.cross_attention_dim])
37-
controlnet_cond = builder.input("controlnet_cond", dtype=ir.DataType.FLOAT, shape=["batch", config.conditioning_channels, "cond_height", "cond_width"])
40+
encoder_hidden_states = builder.input(
41+
"encoder_hidden_states",
42+
dtype=ir.DataType.FLOAT,
43+
shape=["batch", "sequence_length", config.cross_attention_dim],
44+
)
45+
controlnet_cond = builder.input(
46+
"controlnet_cond",
47+
dtype=ir.DataType.FLOAT,
48+
shape=["batch", config.conditioning_channels, "cond_height", "cond_width"],
49+
)
3850

3951
down_outputs, mid_output = module(
4052
op,

src/mobius/tasks/_denoising.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ def build(
3131
graph, builder = _make_graph()
3232
op = builder.op
3333

34-
sample = builder.input("sample", dtype=ir.DataType.FLOAT, shape=["batch", config.in_channels, "height", "width"])
34+
sample = builder.input(
35+
"sample",
36+
dtype=ir.DataType.FLOAT,
37+
shape=["batch", config.in_channels, "height", "width"],
38+
)
3539
timestep = builder.input("timestep", dtype=ir.DataType.INT64, shape=["batch"])
36-
encoder_hidden_states = builder.input("encoder_hidden_states", dtype=ir.DataType.FLOAT, shape=["batch", "sequence_length", config.cross_attention_dim])
40+
encoder_hidden_states = builder.input(
41+
"encoder_hidden_states",
42+
dtype=ir.DataType.FLOAT,
43+
shape=["batch", "sequence_length", config.cross_attention_dim],
44+
)
3745

3846
noise_pred = module(
3947
op,

src/mobius/tasks/_feature_extraction.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ def build(
4141
op = builder.op
4242

4343
input_ids = builder.input("input_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len])
44-
attention_mask = builder.input("attention_mask", dtype=ir.DataType.INT64, shape=[batch, seq_len])
45-
token_type_ids = builder.input("token_type_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len])
44+
attention_mask = builder.input(
45+
"attention_mask", dtype=ir.DataType.INT64, shape=[batch, seq_len]
46+
)
47+
token_type_ids = builder.input(
48+
"token_type_ids", dtype=ir.DataType.INT64, shape=[batch, seq_len]
49+
)
4650

4751
last_hidden_state = module(
4852
op,

0 commit comments

Comments
 (0)