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

Fixed adapter loading for GPTQ base models #58

Merged
merged 2 commits into from
Nov 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ install: gen-server install-torch
run-dev:
# SAFETENSORS_FAST_GPU=1 python -m torch.distributed.run --nproc_per_node=1 lorax_server/cli.py serve meta-llama/Llama-2-7b-hf --sharded
SAFETENSORS_FAST_GPU=1 python -m torch.distributed.run --nproc_per_node=2 lorax_server/cli.py serve mistralai/Mistral-7B-Instruct-v0.1 --sharded
# SAFETENSORS_FAST_GPU=1 python -m torch.distributed.run --nproc_per_node=1 lorax_server/cli.py serve alexsherstinsky/Mistral-7B-v0.1-sharded --sharded
# SAFETENSORS_FAST_GPU=1 python -m torch.distributed.run --nproc_per_node=1 lorax_server/cli.py serve flozi00/Mistral-7B-german-assistant-v5-4bit-autogptq --quantize gptq

export-requirements:
poetry export -o requirements.txt -E bnb -E quantize --without-hashes
16 changes: 14 additions & 2 deletions server/lorax_server/utils/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from functools import lru_cache
from pathlib import Path
from typing import List, Dict, Set, Tuple
import warnings

import torch
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
from loguru import logger
from peft import LoraConfig
from peft.utils import transpose
from safetensors.torch import load_file, save_file
from transformers import AutoConfig
from tqdm import tqdm
from filelock import FileLock

Expand All @@ -27,8 +29,18 @@ def load_module_map(model_id, adapter_id, adapter_source, weight_names):
config_path = get_config_path(adapter_id, adapter_source)
adapter_config = LoraConfig.from_pretrained(config_path)
if adapter_config.base_model_name_or_path != model_id:
flozi00 marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(f"Adapter '{adapter_id}' is not compatible with model '{model_id}'. "
f"Use --model-id '{adapter_config.base_model_name_or_path}' instead.")
expected_config = AutoConfig.from_pretrained(model_id)
model_config = AutoConfig.from_pretrained(adapter_config.base_model_name_or_path)
if model_config.architectures == expected_config.architectures:
warnings.warn(
f"Adapter '{adapter_id}' was not trained on base model '{model_id}'. "
f"If you encounter issues, use --model-id '{adapter_config.base_model_name_or_path}' instead."
)
else:
# TODO(travis): revisit this when we support clasification heads which will not use CausalLM
raise ValueError(f"Adapter '{adapter_id}' is not compatible with model '{model_id}'. "
f"Architectures differ: {model_config.architectures} != {expected_config.architectures}. "
f"Use --model-id '{adapter_config.base_model_name_or_path}' instead.")

# load adapter weights from all shards (should have relatively small memory footprint)
adapter_filenames = source.weight_files()
Expand Down
4 changes: 4 additions & 0 deletions server/lorax_server/utils/gptq/quant_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,7 @@ def forward(self, x):
)
out = out + self.bias if self.bias is not None else out
return out.reshape(out_shape)

@property
def weight(self) -> torch.Tensor:
return self.qweight
Loading