Instructions to use zai-org/chatglm3-6b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/chatglm3-6b with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("zai-org/chatglm3-6b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
修改 quantization.py 中待量化权重的移动逻辑 (#47)
Browse files- 修改 quantization.py 中待量化权重的移动逻辑 (4e17ef37342ef49abe1bfcc54cd43ded06b51347)
Co-authored-by: Miku <MikuRabbit@users.noreply.huggingface.co>
124 unmodified lines12512612712812913013113221 unmodified lines1541551561571581591601 unmodified line1621631641651661671681 unmodified line1701711721731741751761 unmodified line178179180181182183184124 unmodified linesdef __init__(self, weight_bit_width: int, weight, bias=None, device="cpu", dtype=None, empty_init=False, *args,**kwargs):super().__init__()self.weight_bit_width = weight_bit_widthshape = weight.shapeif weight is None or empty_init:21 unmodified linesfor layer in model.layers:layer.self_attention.query_key_value = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.self_attention.query_key_value.weight.to(torch.cuda.current_device()),bias=layer.self_attention.query_key_value.bias,dtype=layer.self_attention.query_key_value.weight.dtype,device=layer.self_attention.query_key_value.weight.device if device is None else device,1 unmodified line)layer.self_attention.dense = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.self_attention.dense.weight.to(torch.cuda.current_device()),bias=layer.self_attention.dense.bias,dtype=layer.self_attention.dense.weight.dtype,device=layer.self_attention.dense.weight.device if device is None else device,1 unmodified line)layer.mlp.dense_h_to_4h = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.mlp.dense_h_to_4h.weight.to(torch.cuda.current_device()),bias=layer.mlp.dense_h_to_4h.bias,dtype=layer.mlp.dense_h_to_4h.weight.dtype,device=layer.mlp.dense_h_to_4h.weight.device if device is None else device,1 unmodified line)layer.mlp.dense_4h_to_h = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.mlp.dense_4h_to_h.weight.to(torch.cuda.current_device()),bias=layer.mlp.dense_4h_to_h.bias,dtype=layer.mlp.dense_4h_to_h.weight.dtype,device=layer.mlp.dense_4h_to_h.weight.device if device is None else device,124 unmodified lines12512612712812913013113213321 unmodified lines1551561571581591601611 unmodified line1631641651661671681691 unmodified line1711721731741751761771 unmodified line179180181182183184185124 unmodified linesdef __init__(self, weight_bit_width: int, weight, bias=None, device="cpu", dtype=None, empty_init=False, *args,**kwargs):super().__init__()assert str(weight.device).startswith('cuda'), 'The weights that need to be quantified should be on the CUDA device'self.weight_bit_width = weight_bit_widthshape = weight.shapeif weight is None or empty_init:21 unmodified linesfor layer in model.layers:layer.self_attention.query_key_value = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.self_attention.query_key_value.weight,bias=layer.self_attention.query_key_value.bias,dtype=layer.self_attention.query_key_value.weight.dtype,device=layer.self_attention.query_key_value.weight.device if device is None else device,1 unmodified line)layer.self_attention.dense = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.self_attention.dense.weight,bias=layer.self_attention.dense.bias,dtype=layer.self_attention.dense.weight.dtype,device=layer.self_attention.dense.weight.device if device is None else device,1 unmodified line)layer.mlp.dense_h_to_4h = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.mlp.dense_h_to_4h.weight,bias=layer.mlp.dense_h_to_4h.bias,dtype=layer.mlp.dense_h_to_4h.weight.dtype,device=layer.mlp.dense_h_to_4h.weight.device if device is None else device,1 unmodified line)layer.mlp.dense_4h_to_h = QuantizedLinear(weight_bit_width=weight_bit_width,weight=layer.mlp.dense_4h_to_h.weight,bias=layer.mlp.dense_4h_to_h.bias,dtype=layer.mlp.dense_4h_to_h.weight.dtype,device=layer.mlp.dense_4h_to_h.weight.device if device is None else device,
quantization.py+6-5