Skip to content

Commit aa21a49

Browse files
authored
Arm backend: Fixup and make docstrings consistent for key functions (#15443)
* Align formatting across key functions and classes of backend * Fix some docstrings Signed-off-by: Tom Allsop <[email protected]>
1 parent 5f2e827 commit aa21a49

File tree

7 files changed

+88
-27
lines changed

7 files changed

+88
-27
lines changed

backends/arm/common/arm_compile_spec.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,30 @@ def to_list(self):
173173
return compile_spec
174174

175175
def get_intermediate_path(self) -> str | None:
176+
"""
177+
Gets the path used for dumping intermediate results such as tosa and pte.
178+
179+
Returns:
180+
Path where intermediate results are saved.
181+
"""
176182
return self.path_for_intermediates
177183

178184
def dump_intermediate_artifacts_to(self, output_path: str | None):
179185
"""
180186
Sets a path for dumping intermediate results during such as tosa and pte.
187+
188+
Args:
189+
output_path: Path to dump intermediate results to.
181190
"""
182191
self.path_for_intermediates = output_path
183192
return self
184193

185194
def dump_debug_info(self, debug_mode: DebugMode | None):
186195
"""
187-
Dump debugging information into the intermediates path
196+
Dump debugging information into the intermediates path.
197+
198+
Args:
199+
debug_mode: The debug mode to use for dumping debug information.
188200
"""
189201
self.tosa_debug_mode = debug_mode
190202
return self

backends/arm/ethosu/compile_spec.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515

1616

1717
class EthosUCompileSpec(ArmCompileSpec):
18+
"""
19+
Compile spec for Ethos-U NPU.
20+
21+
Args:
22+
target: Ethos-U accelerator configuration, e.g. ethos-u55-128.
23+
system_config: System configuration to select from the Vela configuration file.
24+
memory_mode: Memory mode to select from the Vela configuration file.
25+
extra_flags: Extra flags for the Vela compiler.
26+
config_ini: Vela configuration file(s) in Python ConfigParser .ini file format.
27+
"""
1828

1929
_TARGET_KEY = "target"
2030

@@ -26,16 +36,6 @@ def __init__(
2636
extra_flags: list[str] | None = None,
2737
config_ini: str | None = "Arm/vela.ini",
2838
):
29-
"""Generate compile spec for Ethos-U NPU
30-
Args:
31-
target: Ethos-U accelerator configuration, e.g. ethos-u55-128
32-
system_config: System configuration to select from the Vela
33-
configuration file
34-
memory_mode: Memory mode to select from the Vela configuration file
35-
extra_flags: Extra flags for the Vela compiler
36-
config_ini: Vela configuration file(s) in Python ConfigParser .ini
37-
file format
38-
"""
3939
self.target = target
4040

4141
# Set vela compiler flags
@@ -87,6 +87,7 @@ def from_list_hook(cls, compile_spec, specs: dict[str, str]):
8787
compile_spec.target = specs.get(cls._TARGET_KEY, None)
8888

8989
def validate(self):
90+
"""Throws an error if the compile spec is not valid."""
9091
if len(self.compiler_flags) == 0:
9192
raise ValueError(
9293
"compile_flags are required in the CompileSpec list for EthosUBackend"

backends/arm/ethosu/partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class EthosUPartitioner(TOSAPartitioner):
1717
"""
1818
Partitions subgraphs supported by the Arm Ethos-U backend.
1919
20-
Attributes:
20+
Args:
2121
compile_spec: List of CompileSpec objects for Ethos-U backend.
2222
additional_checks: Optional sequence of additional operator support checks.
2323
"""

backends/arm/quantizer/arm_quantizer.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,41 +333,67 @@ def __init__(
333333
self.module_name_config: Dict[str, Optional[QuantizationConfig]] = {}
334334

335335
def set_global(self, quantization_config: QuantizationConfig) -> TOSAQuantizer:
336-
"""Set quantization_config for submodules that are not already annotated by name or type filters."""
336+
"""
337+
Set quantization_config for submodules that are not already annotated by name or type filters.
338+
339+
Args:
340+
quantization_config: The QuantizationConfig to set as global configuration.
341+
"""
337342
self.global_config = quantization_config
338343
return self
339344

340345
def set_module_type(
341346
self, module_type: Callable, quantization_config: QuantizationConfig
342347
) -> TOSAQuantizer:
343-
"""Set quantization_config for a submodule with type: `module_type`, for example:
348+
"""
349+
Set quantization_config for a submodule with type: `module_type`, for example:
344350
quantizer.set_module_name(Sub) or quantizer.set_module_name(nn.Linear), it will quantize all supported operator/operator
345-
patterns in the submodule with this module type with the given `quantization_config`
351+
patterns in the submodule with this module type with the given `quantization_config`.
352+
353+
Args:
354+
module_type: The type of the submodule to set the quantization config for.
355+
quantization_config: The QuantizationConfig to set for the submodule.
346356
"""
347357
self.module_type_config[module_type] = quantization_config
348358
return self
349359

350360
def set_module_name(
351361
self, module_name: str, quantization_config: Optional[QuantizationConfig]
352362
) -> TOSAQuantizer:
353-
"""Set quantization_config for a submodule with name: `module_name`, for example:
363+
"""
364+
Set quantization_config for a submodule with name: `module_name`, for example:
354365
quantizer.set_module_name("blocks.sub"), it will quantize all supported operator/operator
355366
patterns in the submodule with this module name with the given `quantization_config`
367+
368+
Args:
369+
module_name: The name of the submodule to set the quantization config for.
370+
quantization_config: The QuantizationConfig to set for the submodule.
356371
"""
357372
# Validate that quantization_config is provided
358373
if quantization_config is None:
359374
raise ValueError("quantization_config == None is not supported yet")
360375
self.module_name_config[module_name] = quantization_config
361376
return self
362377

363-
def set_io(self, quantization_config):
364-
"""Set quantization_config for input and output nodes."""
378+
def set_io(self, quantization_config: QuantizationConfig) -> TOSAQuantizer:
379+
"""
380+
Set quantization_config for input and output nodes.
381+
382+
Args:
383+
quantization_config: The QuantizationConfig to set for input and output nodes.
384+
"""
365385
self.io_config = quantization_config
366386
return self
367387

368388
def transform_for_annotation(self, model: GraphModule) -> GraphModule:
369-
"""An initial pass for transforming the graph to prepare it for annotation.
389+
"""
390+
An initial pass for transforming the graph to prepare it for annotation.
370391
Currently transforms scalar values to tensor attributes.
392+
393+
Args:
394+
model: The model to transform.
395+
Returns:
396+
The transformed model.
371397
"""
372398

373399
# TODO: Fix the need to lazily import this.
@@ -465,10 +491,24 @@ def validate(self, model: GraphModule) -> None:
465491

466492

467493
class EthosUQuantizer(TOSAQuantizer):
494+
"""
495+
Quantizer supported by the Arm Ethos-U backend.
496+
497+
Args:
498+
compile_spec: A EthosUCompileSpec instance.
499+
"""
500+
468501
def __init__(self, compile_spec: EthosUCompileSpec) -> None:
469502
super().__init__(compile_spec)
470503

471504

472505
class VgfQuantizer(TOSAQuantizer):
506+
"""
507+
Quantizer supported by the Arm Vgf backend.
508+
509+
Args:
510+
compile_spec: A VgfCompileSpec instance.
511+
"""
512+
473513
def __init__(self, compile_spec: VgfCompileSpec) -> None:
474514
super().__init__(compile_spec)

backends/arm/tosa/partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _tag_module( # noqa
193193
"""Tag nodes in a module, possibly a submodule, from the containing program.
194194
195195
Args:
196-
module: a GraphModule from `containing_program` to tag nodes in.
196+
module: A GraphModule from `containing_program` to tag nodes in.
197197
containing_program: The ExportedProgram that contains the module.
198198
reporter: A reporter to report why nodes were rejected.
199199
Returns:

backends/arm/vgf/compile_spec.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616

1717
class VgfCompileSpec(ArmCompileSpec):
18+
"""
19+
Compile spec for VGF compatible targets.
20+
21+
Args:
22+
tosa_spec: TOSA specification that should be targeted.
23+
compiler_flags: Extra compiler flags for converter_backend.
24+
"""
1825

1926
def __init__(
2027
self,
2128
tosa_spec: TosaSpecification | str | None = None,
2229
compiler_flags: list[str] | None = None,
2330
):
24-
"""
25-
Generate compile spec for VGF compatible targets
26-
27-
Args:
28-
compiler_flags: Extra compiler flags for converter_backend
29-
"""
30-
3131
if tosa_spec is None:
3232
tosa_spec = "TOSA-1.0+FP"
3333
if isinstance(tosa_spec, str):

backends/arm/vgf/partitioner.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
@final
1616
class VgfPartitioner(TOSAPartitioner):
17+
"""
18+
Partitions subgraphs supported by the Arm Vgf backend.
19+
20+
Args:
21+
compile_spec: The Vgf compilation specification.
22+
additional_checks: Optional sequence of additional operator support checks.
23+
"""
24+
1725
def __init__(
1826
self,
1927
compile_spec: VgfCompileSpec,

0 commit comments

Comments
 (0)