Skip to content

Commit

Permalink
fix(server): fix bnb quantization for CausalLM models (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierDehaene authored May 31, 2023
1 parent 87dc034 commit 337afb2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/text_generation_server/models/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def linear(input, weight, bias):
return linear

module.linear = replace_linear(state)
else:
tensor = tensor.to(device)
elif quantize == "gptq":
raise NotImplementedError("`gptq` is not implemented for now")
elif quantize is None:
Expand Down
2 changes: 2 additions & 0 deletions server/text_generation_server/models/galactica.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ def linear(input, weight, bias):
return linear

module.linear = replace_linear(state)
else:
tensor = tensor.to(device)
elif quantize == "gptq":
raise NotImplementedError("`gptq` is not implemented for now")
elif quantize is None:
Expand Down
2 changes: 2 additions & 0 deletions server/text_generation_server/models/gpt_neox.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def linear(input, weight, bias):
return linear

module.linear = replace_linear(state)
else:
tensor = tensor.to(device)
elif quantize == "gptq":
raise NotImplementedError("`gptq` is not implemented for now")
elif quantize is None:
Expand Down
9 changes: 7 additions & 2 deletions server/text_generation_server/models/opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def load_weights(

tensor = tensor.contiguous().to(dtype)

if quantize:
if quantize == "bitsandbytes":
if not HAS_BITS_AND_BYTES:
raise ImportError(
"bitsandbytes is not available on your machine either because it is not installed "
Expand Down Expand Up @@ -216,9 +216,14 @@ def linear(input, weight, bias):
return linear

module.linear = replace_linear(state)

else:
tensor = tensor.to(device)
elif quantize == "gptq":
raise NotImplementedError("`gptq` is not implemented for now")
elif quantize is None:
tensor = tensor.to(device)
else:
raise ValueError(f"Unexpected quantize `{quantize}`")

module._parameters[param_name] = tensor
if name == "model.decoder.embed_tokens.weight":
Expand Down
3 changes: 2 additions & 1 deletion server/text_generation_server/models/t5.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def linear(input, weight, bias):
return linear

module.linear = replace_linear(state)

else:
tensor = tensor.to(device)
elif quantize == "gptq" and not module_name.endswith("wo"):
raise NotImplementedError("`gptq` is not implemented for now")
elif quantize is None or module_name.endswith("wo"):
Expand Down

0 comments on commit 337afb2

Please sign in to comment.