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

Function main

examples/qualcomm/oss_scripts/roberta.py:37–158  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

35
36
37def main(args):
38 qnn_config = QnnConfig.load_config(args.config_file if args.config_file else args)
39
40 os.makedirs(args.artifact, exist_ok=True)
41 data_size = 100
42 model_name = "xlm-roberta-base"
43 tokenizer = AutoTokenizer.from_pretrained(model_name)
44 module = AutoModelForMaskedLM.from_pretrained(model_name).eval()
45 pte_filename = "roberta_qnn_q16"
46
47 if args.ci:
48 random_ids = torch.randint(low=0, high=100, size=(1, 100), dtype=torch.int32)
49 attention_mask = create_bidirectional_mask(
50 config=module.config,
51 input_embeds=module.roberta.embeddings(random_ids),
52 attention_mask=torch.zeros((1, 100), dtype=torch.float32),
53 )
54 inputs = [
55 (
56 random_ids,
57 attention_mask,
58 )
59 ]
60 logging.warning(
61 "This option is for CI to verify the export flow. It uses random input and will result in poor accuracy."
62 )
63 else:
64 inputs, targets = get_masked_language_model_dataset(
65 args.dataset, tokenizer, data_size
66 )
67 inputs = [
68 (
69 input_ids,
70 create_bidirectional_mask(
71 config=module.config,
72 input_embeds=module.roberta.embeddings(input_ids),
73 attention_mask=attention_mask,
74 ),
75 )
76 for input_ids, attention_mask in inputs
77 ]
78
79 # lower to QNN
80 quantizer = {
81 QnnExecuTorchBackendType.kGpuBackend: None,
82 QnnExecuTorchBackendType.kHtpBackend: make_quantizer(
83 quant_dtype=QuantDtype.use_16a8w,
84 eps=2**-20,
85 backend=qnn_config.backend,
86 soc_model=qnn_config.soc_model,
87 ),
88 }[qnn_config.backend]
89 build_executorch_binary(
90 model=module,
91 qnn_config=qnn_config,
92 file_name=f"{args.artifact}/{pte_filename}",
93 dataset=inputs,
94 custom_quantizer=quantizer,

Callers 1

roberta.pyFile · 0.70

Calls 15

pushMethod · 0.95
executeMethod · 0.95
pullMethod · 0.95
make_quantizerFunction · 0.90
build_executorch_binaryFunction · 0.90
SimpleADBClass · 0.90
make_output_dirFunction · 0.90
load_configMethod · 0.80
from_pretrainedMethod · 0.80
zerosMethod · 0.80
valuesMethod · 0.80

Tested by

no test coverage detected