Skip to content

Arm backend: Remove hard coded TOSA profile in VGF backend #11818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions backends/arm/arm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
# backends. Converts via TOSA as an intermediate form supported by AoT and
# JIT compiler flows.
#

from typing import List, Optional

from executorch.backends.arm.tosa_specification import TosaSpecification
from executorch.backends.arm.tosa_specification import ( # type: ignore[import-not-found]
TosaSpecification,
)

from executorch.exir.backend.compile_spec_schema import CompileSpec
from executorch.exir.backend.compile_spec_schema import ( # type: ignore[import-not-found]
CompileSpec,
)


class ArmCompileSpecBuilder:
Expand All @@ -28,6 +31,7 @@ def __init__(self):

def vgf_compile_spec(
self,
tosa_spec: TosaSpecification = None, # type: ignore[assignment]
compiler_flags: Optional[str] = "",
) -> "ArmCompileSpecBuilder":
"""
Expand All @@ -40,7 +44,33 @@ def vgf_compile_spec(
self.compiler_flags = [
compiler_flags,
]
self.tosa_spec = TosaSpecification.create_from_string("TOSA-0.80+MI")

if tosa_spec is None:
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+FP")

tosa_version = tosa_spec.version # type: ignore[attr-defined]
tosa_profiles = tosa_spec.profiles # type: ignore[attr-defined]

if tosa_version.major != 1:
raise ValueError(
"Arm backend only supports converter-backend for TOSA version 1. "
f"Invalid TOSA version: {tosa_version}"
)

if not ("FP" or "INT" in tosa_profiles):
raise ValueError(
"Arm backend only supports converter-backend for FP or INT. "
f"Invalid TOSA profile: {tosa_profiles}"
)

if len(tosa_profiles) != 1:
raise ValueError(
"For now Arm backend only supports converter-backend for either FP or INT. "
f"Invalid TOSA profile: {tosa_profiles}"
)

self.tosa_spec = tosa_spec

return self

def ethosu_compile_spec(
Expand Down
9 changes: 8 additions & 1 deletion examples/arm/aot_arm_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def get_compile_spec(
intermediates: Optional[str] = None,
system_config: Optional[str] = None,
memory_mode: Optional[str] = None,
quantize: bool = False,
) -> list[CompileSpec]:
spec_builder = None
if target.startswith("TOSA"):
Expand All @@ -401,7 +402,11 @@ def get_compile_spec(
extra_flags="--verbose-operators --verbose-cycle-estimate",
)
elif "vgf" in target:
spec_builder = ArmCompileSpecBuilder().vgf_compile_spec()
if quantize:
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+INT")
else:
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+FP")
spec_builder = ArmCompileSpecBuilder().vgf_compile_spec(tosa_spec)

if intermediates is not None:
spec_builder.dump_intermediate_artifacts_to(intermediates)
Expand Down Expand Up @@ -700,6 +705,7 @@ def to_edge_TOSA_delegate(
args.intermediates,
args.system_config,
args.memory_mode,
args.quantize,
)

model_int8 = None
Expand Down Expand Up @@ -739,6 +745,7 @@ def to_edge_no_delegate(exported_program, args, model: torch.nn.Module, example_
args.intermediates,
args.system_config,
args.memory_mode,
args.quantize,
)
model, exported_program = quantize_model(
args, model, example_inputs, compile_spec
Expand Down
Loading