Skip to content

Commit 56b19fb

Browse files
Fix lintrunner errors
1 parent 7e6a7d6 commit 56b19fb

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

backends/mediatek/preprocess.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import contextlib
99
import struct
1010

11-
from typing import final, Dict, List
11+
from typing import Dict, final, List
1212

1313
import mtk_converter
1414
import mtk_neuron
@@ -22,7 +22,7 @@
2222
from executorch.exir.backend.compile_spec_schema import CompileSpec
2323

2424
SKIP_COMPILE_SPEC_KEYS = {"ImportForever"}
25-
EXTRACT_SHARED_BLOB_KEY = 'ExtractSharedBlobKey'
25+
EXTRACT_SHARED_BLOB_KEY = "ExtractSharedBlobKey"
2626
HEADER_SIZE = 13
2727
HEADER_VERSION = 1
2828

@@ -45,14 +45,16 @@ def assert_default_dim_order(edge_graph_module: torch.fx.GraphModule) -> None:
4545

4646

4747
def _pack_header(num_inputs, num_outputs, model_bytes_size):
48-
header_bytes = struct.pack("<BIII", HEADER_VERSION, num_inputs, num_outputs, model_bytes_size)
48+
header_bytes = struct.pack(
49+
"<BIII", HEADER_VERSION, num_inputs, num_outputs, model_bytes_size
50+
)
4951
assert len(header_bytes) == HEADER_SIZE
5052
return header_bytes
5153

5254

5355
def _unpack_header(header_bytes):
5456
assert len(header_bytes) == HEADER_SIZE
55-
version, num_inputs, num_outputs, buffer_size = struct.unpack('<BIII', header_bytes)
57+
version, num_inputs, num_outputs, buffer_size = struct.unpack("<BIII", header_bytes)
5658
assert version == HEADER_VERSION
5759
return num_inputs, num_outputs, buffer_size
5860

@@ -89,7 +91,7 @@ def preprocess(
8991
if spec.key in SKIP_COMPILE_SPEC_KEYS:
9092
continue
9193
if spec.key == EXTRACT_SHARED_BLOB_KEY:
92-
compile_options.append('--dla-opt=0')
94+
compile_options.append("--dla-opt=0")
9395
continue
9496

9597
# General compile spec handling
@@ -151,7 +153,7 @@ def preprocess_multimethod(
151153
shared_blob_key = None
152154
for spec in compile_specs[method_name][idx]:
153155
if spec.key == EXTRACT_SHARED_BLOB_KEY:
154-
shared_blob_key = spec.value.decode('utf-8')
156+
shared_blob_key = spec.value.decode("utf-8")
155157

156158
if shared_blob_key is None:
157159
continue
@@ -164,20 +166,26 @@ def preprocess_multimethod(
164166
models_dict[shared_blob_key].append(model_bytes)
165167
result_dict[shared_blob_key].append(result)
166168

167-
data_store_output_dict = dict()
169+
data_store_output_dict = {}
168170
for key, models in models_dict.items():
169171
ndm = NamedDataStore()
170-
blob, new_models = mtk_neuron.extract_shared_data(models, options='-e union')
172+
blob, new_models = mtk_neuron.extract_shared_data(
173+
models, options="-e union"
174+
)
171175
ndm.add_named_data(key, bytes(blob))
172176
data_store_output_dict[key] = ndm.get_named_data_store_output()
173177
models.clear()
174178
models.extend(new_models)
175179

176180
for key, data_store_output in data_store_output_dict.items():
177-
for idx, (model_info, model_bytes) in enumerate(zip(infos_dict[key], models_dict[key])):
181+
for idx, (model_info, model_bytes) in enumerate(
182+
zip(infos_dict[key], models_dict[key])
183+
):
178184
num_inputs, num_outputs = model_info
179185
header_bytes = _pack_header(num_inputs, num_outputs, len(model_bytes))
180186
result_dict[key][idx].data_store_output = data_store_output
181-
result_dict[key][idx].processed_bytes = bytes(header_bytes + model_bytes)
187+
result_dict[key][idx].processed_bytes = bytes(
188+
header_bytes + model_bytes
189+
)
182190

183191
return preprocess_results

examples/mediatek/model_export_scripts/llama.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
NeuropilotQuantizer,
4343
Precision,
4444
)
45-
from executorch.exir.backend.backend_api import to_backend, MethodProgramsPartitionerSpec
45+
from executorch.exir.backend.backend_api import (
46+
MethodProgramsPartitionerSpec,
47+
to_backend,
48+
)
4649
from executorch.exir.backend.backend_details import CompileSpec
4750
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
4851
from tqdm import tqdm
@@ -334,20 +337,22 @@ def export_to_et_ir(
334337

335338
method_to_edge_program = {}
336339
method_to_partitioner = {}
337-
edge_compile_config=exir.EdgeCompileConfig(_check_ir_validity=False)
340+
edge_compile_config = exir.EdgeCompileConfig(_check_ir_validity=False)
338341

339-
model_shared_key_name = f'{exp_name}_{chunk_idx}'
342+
model_shared_key_name = f"{exp_name}_{chunk_idx}"
340343

341344
# Fixed Shape Export Here
342345
for shape, ntok_and_cache in export_shapes.items():
343-
model_fname = f'{exp_name}_{shape}_{chunk_idx}'
346+
model_fname = f"{exp_name}_{shape}_{chunk_idx}"
344347
example_inputs = model.get_example_inputs(*ntok_and_cache)
345348
print(f"Getting ATen Dialect Graph for {exp_name} {shape} chunk {chunk_idx}")
346349
aten_dialect: exir.ExportedProgram = torch.export.export(
347350
converted_graph, example_inputs, strict=True
348351
)
349352

350-
method_to_edge_program[f'{model_fname}'] = exir.to_edge(aten_dialect).exported_program()
353+
method_to_edge_program[f"{model_fname}"] = exir.to_edge(
354+
aten_dialect
355+
).exported_program()
351356
del aten_dialect
352357

353358
compile_spec = [
@@ -357,19 +362,15 @@ def export_to_et_ir(
357362
CompileSpec("ImportForever", struct.pack("?", True)),
358363
CompileSpec("ExtractSharedBlobKey", model_shared_key_name.encode()),
359364
]
360-
method_to_partitioner[f'{model_fname}'] = NeuropilotPartitioner(compile_spec)
365+
method_to_partitioner[f"{model_fname}"] = NeuropilotPartitioner(compile_spec)
361366

362367
print("Delegating Edge Program to Neuropilot Backend")
363368
delegated_program = to_backend(
364-
MethodProgramsPartitionerSpec(
365-
method_to_edge_program,
366-
method_to_partitioner
367-
)
369+
MethodProgramsPartitionerSpec(method_to_edge_program, method_to_partitioner)
368370
)
369371

370372
edge_manager = exir.EdgeProgramManager(
371-
delegated_program,
372-
compile_config=edge_compile_config
373+
delegated_program, compile_config=edge_compile_config
373374
)
374375
del delegated_program
375376

@@ -384,7 +385,7 @@ def export_to_et_ir(
384385
)
385386
)
386387
del edge_manager
387-
print(f'\n Model Size: {len(executorch_program.buffer)}')
388+
print(f"\n Model Size: {len(executorch_program.buffer)}")
388389

389390
dest_path = get_dest_path(output_folder, exp_name, None, chunk_idx)
390391
print(f"{exp_name} ET Model chunk {chunk_idx} Dest: {dest_path}\n")

0 commit comments

Comments
 (0)