Export each requested component to an ExportedProgram.
(
checkpoint_path: str,
text_quantize: str,
audio_quantize: str,
vision_quantize: str,
max_seq_len: int,
max_patches: int,
group_size: int,
tied_embedding: bool,
variant: str,
quantize_kv_cache: bool,
include_audio: bool,
include_vision: bool,
use_custom_sdpa: bool,
)
| 546 | |
| 547 | |
| 548 | def _export_components( |
| 549 | checkpoint_path: str, |
| 550 | text_quantize: str, |
| 551 | audio_quantize: str, |
| 552 | vision_quantize: str, |
| 553 | max_seq_len: int, |
| 554 | max_patches: int, |
| 555 | group_size: int, |
| 556 | tied_embedding: bool, |
| 557 | variant: str, |
| 558 | quantize_kv_cache: bool, |
| 559 | include_audio: bool, |
| 560 | include_vision: bool, |
| 561 | use_custom_sdpa: bool, |
| 562 | ) -> dict: |
| 563 | """Export each requested component to an ExportedProgram.""" |
| 564 | components = [] |
| 565 | if include_audio: |
| 566 | components += ["speech_transform", "audio_encoder"] |
| 567 | if include_vision: |
| 568 | components += ["vision_encoder"] |
| 569 | components += ["text_decoder"] |
| 570 | num_components = len(components) |
| 571 | logger.info(f"Exporting {num_components} methods: {', '.join(components)}") |
| 572 | |
| 573 | programs = {} |
| 574 | step = 0 |
| 575 | |
| 576 | if include_audio: |
| 577 | step += 1 |
| 578 | logger.info(f"[{step}/{num_components}] Exporting speech transform...") |
| 579 | programs["speech_transform"] = _export_speech_transform(checkpoint_path) |
| 580 | |
| 581 | step += 1 |
| 582 | logger.info(f"[{step}/{num_components}] Exporting audio encoder...") |
| 583 | programs["audio_encoder"] = _export_audio_encoder( |
| 584 | checkpoint_path, audio_quantize, group_size=group_size |
| 585 | ) |
| 586 | |
| 587 | if include_vision: |
| 588 | step += 1 |
| 589 | logger.info(f"[{step}/{num_components}] Exporting vision encoder...") |
| 590 | programs["vision_encoder"] = _export_vision_encoder( |
| 591 | checkpoint_path, |
| 592 | vision_quantize, |
| 593 | group_size=group_size, |
| 594 | max_patches=max_patches, |
| 595 | ) |
| 596 | |
| 597 | step += 1 |
| 598 | logger.info(f"[{step}/{num_components}] Exporting text decoder...") |
| 599 | programs["text_decoder"] = _export_text_decoder( |
| 600 | checkpoint_path, |
| 601 | text_quantize, |
| 602 | max_seq_len, |
| 603 | group_size=group_size, |
| 604 | tied_embedding=tied_embedding, |
| 605 | variant=variant, |
no test coverage detected