Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion interleaved_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ def split_token_sequence(
def main(args: argparse.Namespace):
"""Main function to generate and process model output."""
# Load Chameleon model
model = ChameleonInferenceModel(
unquantized_model = ChameleonInferenceModel(
MODEL_7B_PATH.as_posix(),
TOKENIZER_TEXT_PATH.as_posix(),
TOKENIZER_IMAGE_CFG_PATH.as_posix(),
TOKENIZER_IMAGE_PATH.as_posix(),
)
model = torch.quantization.quantize_dynamic(
unquantized_model, # The model to be quantized
{torch.nn.Linear, torch.nn.LSTM}, # Layers to be dynamically quantized
dtype=torch.qint8 # Data type for quantization
)
# Print model configuration
print(f"Model path: {MODEL_7B_PATH}")
print(f"Text tokenizer path: {TOKENIZER_TEXT_PATH}")
Expand Down
8 changes: 6 additions & 2 deletions text2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ def main(args: argparse.Namespace):
print(f"Batch size: {args.batch_size}")

# Load Chameleon model
model = ChameleonInferenceModel(
unquantized_model = ChameleonInferenceModel(
MODEL_7B_PATH.as_posix(),
TOKENIZER_TEXT_PATH.as_posix(),
TOKENIZER_IMAGE_CFG_PATH.as_posix(),
TOKENIZER_IMAGE_PATH.as_posix(),
)

model = torch.quantization.quantize_dynamic(
unquantized_model, # The model to be quantized
{torch.nn.Linear, torch.nn.LSTM}, # Layers to be dynamically quantized
dtype=torch.qint8 # Data type for quantization
)
# Generate options
options = Options()
options.txt = False
Expand Down