MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / quantize_model

Method quantize_model

optillm/inference.py:1007–1022  ·  view source on GitHub ↗

Quantize model to 4-bit precision using bitsandbytes

(self, model)

Source from the content-addressed store, hash-verified

1005 self.device_manager = device_manager
1006
1007 def quantize_model(self, model):
1008 """Quantize model to 4-bit precision using bitsandbytes"""
1009 def _replace_linear_layers(module):
1010 for name, child in module.named_children():
1011 if isinstance(child, torch.nn.Linear):
1012 setattr(module, name, bnb.nn.Linear4bit(
1013 child.in_features,
1014 child.out_features,
1015 bias=child.bias is not None,
1016 compute_dtype=torch.float16
1017 ))
1018 else:
1019 _replace_linear_layers(child)
1020
1021 _replace_linear_layers(model)
1022 return model
1023
1024 def load_base_model(self, model_id: str, quantize: bool = True) -> Tuple[AutoModelForCausalLM, AutoTokenizer]:
1025 def _load_model():

Callers 1

_load_modelMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected