MCPcopy Create free account
hub / github.com/pytorch/executorch / get_encoding

Function get_encoding

examples/qualcomm/qaihub_scripts/utils/utils.py:24–58  ·  view source on GitHub ↗
(
    path_to_shard: str,
    compiler_specs: str,
    get_input: bool,
    get_output: bool,
    num_input: int,
    num_output: int,
)

Source from the content-addressed store, hash-verified

22
23
24def get_encoding(
25 path_to_shard: str,
26 compiler_specs: str,
27 get_input: bool,
28 get_output: bool,
29 num_input: int,
30 num_output: int,
31):
32 encoding_list = []
33 with open(path_to_shard, "rb") as f:
34 ctx_bin = preprocess_binary(f.read(), compiler_specs)
35 qnn_mgr = PyQnnManagerAdaptor.QnnManager(
36 generate_qnn_executorch_option(compiler_specs), ctx_bin
37 )
38 assert qnn_mgr.Init().value == 0, "failed to load context binary"
39 graph_name = qnn_mgr.GetGraphNames()[0]
40 qnn_mgr.AllocateTensor(graph_name)
41 if get_input:
42 encoding_input = {"scale": [], "offset": []}
43 for i in range(num_input):
44 inputs = qnn_mgr.GetGraphInputs(graph_name)[i]
45 encoding = inputs.GetEncodings()
46 encoding_input["scale"].append(encoding.data["scale"].item())
47 encoding_input["offset"].append(encoding.data["offset"].item())
48 encoding_list.append(encoding_input)
49 if get_output:
50 encoding_output = {"scale": [], "offset": []}
51 for i in range(num_output):
52 outputs = qnn_mgr.GetGraphOutputs(graph_name)[i]
53 encoding = outputs.GetEncodings()
54 encoding_output["scale"].append(encoding.data["scale"].item())
55 encoding_output["offset"].append(encoding.data["offset"].item())
56 encoding_list.append(encoding_output)
57 qnn_mgr.Destroy()
58 return encoding_list
59
60
61def gen_pte_from_ctx_bin(artifact, pte_names, bundle_programs, backend_config):

Callers 3

mainFunction · 0.90
mainFunction · 0.90
get_encodingsFunction · 0.90

Calls 4

preprocess_binaryFunction · 0.70
InitMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected