Main entry point of our function which compiles and generates our model data.
(
self,
metadata: NetworkMetadata,
network_input: List[str],
working_directory: str,
keep_onnx_model: bool,
keep_pytorch_model: bool,
timing_profile: TimingProfile,
use_cpu: bool = False,
batch_size: int = 1,
args: object = None,
benchmarking_mode: bool = False,
perplexity_reference: List[str] = None,
)
| 316 | return perplexity |
| 317 | |
| 318 | def run_framework( |
| 319 | self, |
| 320 | metadata: NetworkMetadata, |
| 321 | network_input: List[str], |
| 322 | working_directory: str, |
| 323 | keep_onnx_model: bool, |
| 324 | keep_pytorch_model: bool, |
| 325 | timing_profile: TimingProfile, |
| 326 | use_cpu: bool = False, |
| 327 | batch_size: int = 1, |
| 328 | args: object = None, |
| 329 | benchmarking_mode: bool = False, |
| 330 | perplexity_reference: List[str] = None, |
| 331 | ) -> Union[List[NetworkResult], BenchmarkingResult]: |
| 332 | """ |
| 333 | Main entry point of our function which compiles and generates our model data. |
| 334 | """ |
| 335 | inference_results = [] |
| 336 | ppl_results = [] |
| 337 | workspace = NNFolderWorkspace( |
| 338 | self.config.network_name, metadata, working_directory |
| 339 | ) |
| 340 | try: |
| 341 | network_fpaths = self.generate_and_download_framework(metadata, workspace) |
| 342 | if not benchmarking_mode: |
| 343 | for ninput in network_input: |
| 344 | inference_results.append( |
| 345 | self.execute_inference( |
| 346 | metadata, network_fpaths, ninput, timing_profile, use_cpu, batch_size, args.num_beams |
| 347 | ) |
| 348 | ) |
| 349 | if perplexity_reference is not None: |
| 350 | assert len(network_input) == len(perplexity_reference), "Encoder and decoder inputs must pair up" |
| 351 | for ei, di in zip(network_input, perplexity_reference): |
| 352 | ppl_results.append( |
| 353 | self.execute_calculate_perplexity( |
| 354 | metadata, network_fpaths, ei, di |
| 355 | ) |
| 356 | ) |
| 357 | else: |
| 358 | benchmarking_args = BARTBenchmarkingArgs(args.input_seq_len, args.output_seq_len) |
| 359 | inference_results = self.execute_inference( |
| 360 | metadata, network_fpaths, None, timing_profile, use_cpu, batch_size, args.num_beams, True, benchmarking_args |
| 361 | ) |
| 362 | finally: |
| 363 | self.cleanup(workspace, keep_onnx_model, keep_pytorch_model) |
| 364 | |
| 365 | return inference_results, ppl_results |
| 366 | |
| 367 | |
| 368 | # Entry point |
nothing calls this directly
no test coverage detected