Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: quantization added #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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