This is a dynamically quantized INT8 version of
gvs/wav2vec2-large-xlsr-malayalam.
This version is highly optimized for CPU inference, reducing size to approx 338.16 MB.
Because this model uses PyTorch's native dynamic quantization, it cannot be loaded using the standard from_pretrained method alone. You must build the base architecture, quantize it to match, and then load the weights.
1import torch
2from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
3from huggingface_hub import hf_hub_download
4
5repo_id = "trysem/wav2vec2-malayalam-int8"
6
7# 1. Load the processor and empty base architecture from this repo
8processor = Wav2Vec2Processor.from_pretrained(repo_id)
9base_model = Wav2Vec2ForCTC.from_pretrained(repo_id)
10
11# 2. Apply dynamic quantization to the skeleton
12quantized_model = torch.quantization.quantize_dynamic(
13 base_model, {torch.nn.Linear}, dtype=torch.qint8
14)
15
16# 3. Download and load the INT8 weights
17weight_path = hf_hub_download(repo_id=repo_id, filename="quantized_model_int8.pt")
18quantized_model.load_state_dict(torch.load(weight_path))
19
20print("Model successfully loaded!")