Skip to content

Commit 93edd5c

Browse files
justinchubyCopilot
andcommitted
Fix LFM2 CUDA causal convolution lowering
Inline CausalConvWithState only for CUDA optimized models so ORT can assign the standard convolution body to CUDA. Preserve the local function for portable CPU builds and add full-logit cached decode parity coverage for both paths. Refresh test imports and mocks for the weight-loading and builder integration refactors on current main. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent f3371b1 commit 93edd5c

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

‎src/mobius/_optimizations.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ def _should_inline(func: ir.Function) -> bool:
452452
# ops like CausalConvWithState and LinearAttention registered per-model.
453453
if caps.name == "onnx-standard" and func.domain not in _STANDARD_ONNX_DOMAINS:
454454
return True
455+
# ORT's CUDA EP has no CausalConvWithState kernel. Keeping the local
456+
# function call causes TransformerMemcpy to inspect a node without a
457+
# provider assignment and abort session initialization. Inline its
458+
# standard Conv-based body so hybrid decoders run on CUDA.
459+
if (
460+
caps.name == "cuda"
461+
and func.domain == "com.microsoft"
462+
and func.name == "CausalConvWithState"
463+
):
464+
return True
455465
if func.domain == "com.microsoft" and func.name in (
456466
"SkipLayerNormalization",
457467
"SkipSimplifiedLayerNormalization",

‎src/mobius/components/_siglip2_naflex_test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from mobius._configs import VisionConfig
1212
from mobius._testing.ort_inference import OnnxModelSession
13-
from mobius._weight_loading import apply_weights
1413
from mobius.components import Siglip2NaFlexVisionModel
14+
from mobius.integrations._weight_loading import apply_weights
1515
from mobius.tasks._base import _make_graph, _make_model
1616

1717
_HIDDEN_SIZE = 32

‎src/mobius/integrations/ort_genai/auto_export_test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,7 @@ def fake_export_package(pkg, output_dir, **kwargs):
27282728
return {"genai_config": os.path.join(output_dir, "genai_config.json")}
27292729

27302730
with (
2731-
mock.patch("mobius._builder.build", side_effect=fake_build),
2731+
mock.patch("mobius.integrations.transformers.build", side_effect=fake_build),
27322732
mock.patch(
27332733
"mobius.integrations.ort_genai.auto_export.export_package",
27342734
side_effect=fake_export_package,

‎src/mobius/models/lfm2_test.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ def test_cuda_graph_uses_lfm2_fusions():
9797

9898
counts = Counter((node.domain or "", node.op_type) for node in model.graph)
9999
assert counts["", "Swish"] == 2
100-
assert counts["com.microsoft", "CausalConvWithState"] == 1
100+
# CUDA has no CausalConvWithState kernel. Its standard Conv function body
101+
# must be inlined or ORT aborts while assigning providers.
102+
assert counts["com.microsoft", "CausalConvWithState"] == 0
103+
assert counts["", "Conv"] == 1
101104
assert counts["com.microsoft", "SkipSimplifiedLayerNormalization"] == 4
102105

103106
remaining_norms = [node for node in model.graph if node.op_type == "RMSNormalization"]

‎src/mobius/models/lfm2_vl_test.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
import pytest
1111
import torch
1212

13+
from mobius import build_from_module
1314
from mobius._configs import Lfm2VlConfig
1415
from mobius._testing.ort_inference import OnnxModelSession
15-
from mobius._weight_loading import apply_weights
16+
from mobius.integrations._weight_loading import apply_weights
1617
from mobius.models.lfm2_vl import Lfm2VlForConditionalGeneration
1718
from mobius.tasks import Lfm2VlTask
1819

@@ -341,14 +342,20 @@ def _empty_decoder_cache(config: Lfm2VlConfig, batch: int) -> dict[str, np.ndarr
341342
return feeds
342343

343344

344-
def test_decoder_matches_transformers_on_prefill_and_cached_decode():
345+
@pytest.mark.parametrize("execution_provider", ["default", "cuda"])
346+
def test_decoder_matches_transformers_on_prefill_and_cached_decode(execution_provider: str):
345347
"""L3: the inputs_embeds decoder and hybrid cache match HF step for step."""
346348
torch.manual_seed(11)
347349
hf_model = _hf_causal_lm()
348350

349351
config = _tiny_config()
350352
module = Lfm2VlForConditionalGeneration(config)
351-
package = Lfm2VlTask().build(module, config)
353+
package = build_from_module(
354+
module,
355+
config,
356+
task="lfm2-vl",
357+
execution_provider=execution_provider,
358+
)
352359

353360
state_dict = {
354361
f"model.language_model.{name[len('model.') :]}": value

‎tests/cli_test.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def test_build_propagates_revision(self):
534534
with (
535535
tempfile.TemporaryDirectory() as tmpdir,
536536
mock.patch(
537-
"mobius._diffusers_builder._load_diffusers_pipeline_index",
537+
"mobius.integrations.diffusers._builder._load_diffusers_pipeline_index",
538538
return_value=None,
539539
) as detect_diffusers,
540540
mock.patch("mobius.__main__.build", return_value=mock.MagicMock()) as build_model,

0 commit comments

Comments
 (0)