Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/src/coreai_models/export/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def palettize_pytorch_model(
model: nn.Module,
example_inputs: tuple,
palettization_config: "dict | KMeansPalettizerConfig",
export_backend: ExportBackend = ExportBackend.CoreAI,
) -> nn.Module:
"""
Palettize a PyTorch model using post-training palettization with coreai-opt.
Expand All @@ -337,6 +338,7 @@ def palettize_pytorch_model(
palettization_config: Either a configuration dictionary (matching the
inner shape coreai-opt expects under `kmeans_palettization_config`)
or a prebuilt KMeansPalettizerConfig instance.
export_backend: Backend for the finalized palettized model.

Returns:
Palettized model ready for export.
Expand All @@ -359,7 +361,7 @@ def palettize_pytorch_model(
palettizer = KMeansPalettizer(model, config)
prepared_model = palettizer.prepare(example_inputs=example_inputs, num_workers=32)

finalized_model = palettizer.finalize(prepared_model, backend=ExportBackend.CoreAI)
finalized_model = palettizer.finalize(prepared_model, backend=export_backend)

logger.info("Palettization with coreai-opt complete")
return finalized_model