2022-10-18 07:19:03 -06:00
|
|
|
import os
|
2023-01-05 04:01:23 -07:00
|
|
|
import sys
|
2022-10-17 06:59:00 -06:00
|
|
|
import typer
|
|
|
|
|
|
|
|
from pathlib import Path
|
2023-01-05 04:01:23 -07:00
|
|
|
from loguru import logger
|
2024-07-26 08:29:09 -06:00
|
|
|
from typing import Optional
|
2023-05-12 06:46:41 -06:00
|
|
|
from enum import Enum
|
feat(server): Add native support for PEFT Lora models (#762)
- Will detect `peft` model by finding `adapter_config.json`.
- This triggers a totally dedicated `download-weights` path
- This path, loads the adapter config, finds the base model_id
- It loads the base_model
- Then peft_model
- Then `merge_and_unload()`
- Then `save_pretrained(.., safe_serialization=True)
- Add back the config + tokenizer.merge_and_unload()`
- Then `save_pretrained(.., safe_serialization=True)
- Add back the config + tokenizer.
- The chosen location is a **local folder with the name of the user
chosen model id**
PROs:
- Easier than to expect user to merge manually
- Barely any change outside of `download-weights` command.
- This means everything will work in a single load.
- Should enable out of the box SM + HFE
CONs:
- Creates a local merged model in unusual location, potentially
not saved across docker reloads, or ovewriting some files if the PEFT
itself was local and containing other files in addition to the lora
Alternatives considered:
- Add `local_files_only=True` every where (discard because of massive
code change for not a good enough reason)
- Return something to `launcher` about the new model-id (a cleaner
location for this new model), but it would
introduce new communication somewhere where we didn't need it before.
- Using the HF cache folder and *stopping* the flow after
`download-weights` and asking user to restart with the actual local
model location
Fix #482
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2023-08-03 09:22:45 -06:00
|
|
|
from huggingface_hub import hf_hub_download
|
2024-07-24 13:32:14 -06:00
|
|
|
from text_generation_server.utils.adapter import parse_lora_adapters
|
2022-10-17 06:59:00 -06:00
|
|
|
|
|
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
|
2023-05-12 06:46:41 -06:00
|
|
|
class Quantization(str, Enum):
|
|
|
|
bitsandbytes = "bitsandbytes"
|
2023-08-03 15:00:59 -06:00
|
|
|
bitsandbytes_nf4 = "bitsandbytes-nf4"
|
|
|
|
bitsandbytes_fp4 = "bitsandbytes-fp4"
|
2023-05-12 06:46:41 -06:00
|
|
|
gptq = "gptq"
|
Add AWQ quantization inference support (#1019) (#1054)
# Add AWQ quantization inference support
Fixes
https://github.com/huggingface/text-generation-inference/issues/781
This PR (partially) adds support for AWQ quantization for inference.
More information on AWQ [here](https://arxiv.org/abs/2306.00978). In
general, AWQ is faster and more accurate than GPTQ, which is currently
supported by TGI.
This PR installs 4-bit GEMM custom CUDA kernels released by AWQ authors
(in `requirements.txt`, just one line change).
Quick way to test this PR would be bring up TGI as follows:
```
text-generation-server download-weights abhinavkulkarni/codellama-CodeLlama-7b-Python-hf-w4-g128-awq
text-generation-launcher \
--huggingface-hub-cache ~/.cache/huggingface/hub/ \
--model-id abhinavkulkarni/codellama-CodeLlama-7b-Python-hf-w4-g128-awq \
--trust-remote-code --port 8080 \
--max-input-length 2048 --max-total-tokens 4096 --max-batch-prefill-tokens 4096 \
--quantize awq
```
Please note:
* This PR was tested with FlashAttention v2 and vLLM.
* This PR adds support for AWQ inference, not quantizing the models.
That needs to be done outside of TGI, instructions
[here](https://github.com/mit-han-lab/llm-awq/tree/f084f40bd996f3cf3a0633c1ad7d9d476c318aaa).
* This PR only adds support for `FlashLlama` models for now.
* Multi-GPU setup has not been tested.
* No integration tests have been added so far, will add later if
maintainers are interested in this change.
* This PR can be tested on any of the models released
[here](https://huggingface.co/abhinavkulkarni?sort_models=downloads#models).
Please refer to the linked issue for benchmarks for
[abhinavkulkarni/meta-llama-Llama-2-7b-chat-hf-w4-g128-awq](https://huggingface.co/abhinavkulkarni/meta-llama-Llama-2-7b-chat-hf-w4-g128-awq)
vs
[TheBloke/Llama-2-7b-Chat-GPTQ](https://huggingface.co/TheBloke/Llama-2-7b-Chat-GPTQ).
Please note, AWQ has released faster (and in case of Llama, fused)
kernels for 4-bit GEMM, currently at the top of the `main` branch at
https://github.com/mit-han-lab/llm-awq, but this PR uses an older commit
that has been tested to work. We can switch to latest commit later on.
## Who can review?
@OlivierDehaene OR @Narsil
---------
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Abhinav M Kulkarni <abhinavkulkarni@gmail.com>
Co-authored-by: Abhinav Kulkarni <abhinav@concentric.ai>
2023-09-25 07:31:27 -06:00
|
|
|
awq = "awq"
|
2023-09-27 03:42:57 -06:00
|
|
|
eetq = "eetq"
|
2024-05-28 03:51:31 -06:00
|
|
|
exl2 = "exl2"
|
2024-04-12 00:13:30 -06:00
|
|
|
fp8 = "fp8"
|
2024-06-05 02:14:40 -06:00
|
|
|
marlin = "marlin"
|
2023-05-12 06:46:41 -06:00
|
|
|
|
|
|
|
|
2023-06-30 12:30:09 -06:00
|
|
|
class Dtype(str, Enum):
|
|
|
|
float16 = "float16"
|
|
|
|
bloat16 = "bfloat16"
|
|
|
|
|
|
|
|
|
2022-10-17 06:59:00 -06:00
|
|
|
@app.command()
|
2022-10-18 07:19:03 -06:00
|
|
|
def serve(
|
2023-02-03 04:43:37 -07:00
|
|
|
model_id: str,
|
2023-01-31 10:53:56 -07:00
|
|
|
revision: Optional[str] = None,
|
2022-10-18 07:19:03 -06:00
|
|
|
sharded: bool = False,
|
2023-05-12 06:46:41 -06:00
|
|
|
quantize: Optional[Quantization] = None,
|
2023-12-11 04:46:30 -07:00
|
|
|
speculate: Optional[int] = None,
|
2023-06-30 12:30:09 -06:00
|
|
|
dtype: Optional[Dtype] = None,
|
2023-05-23 12:40:39 -06:00
|
|
|
trust_remote_code: bool = False,
|
2023-03-30 07:26:27 -06:00
|
|
|
uds_path: Path = "/tmp/text-generation-server",
|
2023-01-05 04:01:23 -07:00
|
|
|
logger_level: str = "INFO",
|
|
|
|
json_output: bool = False,
|
2023-02-13 05:02:45 -07:00
|
|
|
otlp_endpoint: Optional[str] = None,
|
2024-06-25 01:33:01 -06:00
|
|
|
otlp_service_name: str = "text-generation-inference.server",
|
2024-06-10 01:09:50 -06:00
|
|
|
max_input_tokens: Optional[int] = None,
|
2022-10-17 06:59:00 -06:00
|
|
|
):
|
2022-10-18 07:19:03 -06:00
|
|
|
if sharded:
|
|
|
|
assert (
|
|
|
|
os.getenv("RANK", None) is not None
|
|
|
|
), "RANK must be set when sharded is True"
|
|
|
|
assert (
|
|
|
|
os.getenv("WORLD_SIZE", None) is not None
|
|
|
|
), "WORLD_SIZE must be set when sharded is True"
|
|
|
|
assert (
|
|
|
|
os.getenv("MASTER_ADDR", None) is not None
|
|
|
|
), "MASTER_ADDR must be set when sharded is True"
|
|
|
|
assert (
|
|
|
|
os.getenv("MASTER_PORT", None) is not None
|
|
|
|
), "MASTER_PORT must be set when sharded is True"
|
|
|
|
|
2023-02-13 05:02:45 -07:00
|
|
|
# Remove default handler
|
|
|
|
logger.remove()
|
|
|
|
logger.add(
|
|
|
|
sys.stdout,
|
|
|
|
format="{message}",
|
2023-03-07 10:52:22 -07:00
|
|
|
filter="text_generation_server",
|
2023-02-13 05:02:45 -07:00
|
|
|
level=logger_level,
|
|
|
|
serialize=json_output,
|
|
|
|
backtrace=True,
|
|
|
|
diagnose=False,
|
|
|
|
)
|
2023-04-16 16:26:47 -06:00
|
|
|
|
|
|
|
# Import here after the logger is added to log potential import exceptions
|
|
|
|
from text_generation_server import server
|
|
|
|
from text_generation_server.tracing import setup_tracing
|
|
|
|
|
2023-02-13 05:02:45 -07:00
|
|
|
# Setup OpenTelemetry distributed tracing
|
|
|
|
if otlp_endpoint is not None:
|
2024-06-25 01:33:01 -06:00
|
|
|
setup_tracing(otlp_service_name=otlp_service_name, otlp_endpoint=otlp_endpoint)
|
2023-02-13 05:02:45 -07:00
|
|
|
|
2024-07-24 13:32:14 -06:00
|
|
|
lora_adapters = parse_lora_adapters(os.getenv("LORA_ADAPTERS"))
|
2024-06-25 12:46:27 -06:00
|
|
|
|
2024-07-15 07:16:15 -06:00
|
|
|
# TODO: enable lora with cuda graphs. for now disable cuda graphs if lora is enabled
|
|
|
|
# and warn the user
|
2024-07-24 13:32:14 -06:00
|
|
|
if lora_adapters:
|
|
|
|
logger.warning("LoRA adapters enabled (experimental feature).")
|
|
|
|
|
|
|
|
if "CUDA_GRAPHS" in os.environ:
|
|
|
|
logger.warning(
|
|
|
|
"LoRA adapters incompatible with CUDA Graphs. Disabling CUDA Graphs."
|
|
|
|
)
|
|
|
|
global CUDA_GRAPHS
|
|
|
|
CUDA_GRAPHS = None
|
2024-07-15 07:16:15 -06:00
|
|
|
|
2023-05-12 06:46:41 -06:00
|
|
|
# Downgrade enum into str for easier management later on
|
|
|
|
quantize = None if quantize is None else quantize.value
|
2023-06-30 12:30:09 -06:00
|
|
|
dtype = None if dtype is None else dtype.value
|
2023-12-11 06:49:52 -07:00
|
|
|
if dtype is not None and quantize not in {
|
|
|
|
None,
|
|
|
|
"bitsandbytes",
|
|
|
|
"bitsandbytes-nf4",
|
|
|
|
"bitsandbytes-fp4",
|
|
|
|
}:
|
2023-06-30 12:30:09 -06:00
|
|
|
raise RuntimeError(
|
|
|
|
"Only 1 can be set between `dtype` and `quantize`, as they both decide how goes the final model."
|
|
|
|
)
|
|
|
|
server.serve(
|
2023-12-11 06:49:52 -07:00
|
|
|
model_id,
|
2024-07-24 13:32:14 -06:00
|
|
|
lora_adapters,
|
2023-12-11 06:49:52 -07:00
|
|
|
revision,
|
|
|
|
sharded,
|
|
|
|
quantize,
|
|
|
|
speculate,
|
|
|
|
dtype,
|
|
|
|
trust_remote_code,
|
|
|
|
uds_path,
|
2024-06-10 01:09:50 -06:00
|
|
|
max_input_tokens,
|
2023-06-30 12:30:09 -06:00
|
|
|
)
|
2022-10-17 06:59:00 -06:00
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
2022-10-22 12:00:15 -06:00
|
|
|
def download_weights(
|
2023-02-03 04:43:37 -07:00
|
|
|
model_id: str,
|
2023-01-31 10:53:56 -07:00
|
|
|
revision: Optional[str] = None,
|
2022-10-28 11:24:00 -06:00
|
|
|
extension: str = ".safetensors",
|
2023-05-03 03:36:24 -06:00
|
|
|
auto_convert: bool = True,
|
2023-02-14 05:02:16 -07:00
|
|
|
logger_level: str = "INFO",
|
|
|
|
json_output: bool = False,
|
feat(server): Add native support for PEFT Lora models (#762)
- Will detect `peft` model by finding `adapter_config.json`.
- This triggers a totally dedicated `download-weights` path
- This path, loads the adapter config, finds the base model_id
- It loads the base_model
- Then peft_model
- Then `merge_and_unload()`
- Then `save_pretrained(.., safe_serialization=True)
- Add back the config + tokenizer.merge_and_unload()`
- Then `save_pretrained(.., safe_serialization=True)
- Add back the config + tokenizer.
- The chosen location is a **local folder with the name of the user
chosen model id**
PROs:
- Easier than to expect user to merge manually
- Barely any change outside of `download-weights` command.
- This means everything will work in a single load.
- Should enable out of the box SM + HFE
CONs:
- Creates a local merged model in unusual location, potentially
not saved across docker reloads, or ovewriting some files if the PEFT
itself was local and containing other files in addition to the lora
Alternatives considered:
- Add `local_files_only=True` every where (discard because of massive
code change for not a good enough reason)
- Return something to `launcher` about the new model-id (a cleaner
location for this new model), but it would
introduce new communication somewhere where we didn't need it before.
- Using the HF cache folder and *stopping* the flow after
`download-weights` and asking user to restart with the actual local
model location
Fix #482
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2023-08-03 09:22:45 -06:00
|
|
|
trust_remote_code: bool = False,
|
2024-06-25 12:46:27 -06:00
|
|
|
merge_lora: bool = False,
|
2022-10-17 06:59:00 -06:00
|
|
|
):
|
2023-02-14 05:02:16 -07:00
|
|
|
# Remove default handler
|
|
|
|
logger.remove()
|
|
|
|
logger.add(
|
|
|
|
sys.stdout,
|
|
|
|
format="{message}",
|
2023-03-07 10:52:22 -07:00
|
|
|
filter="text_generation_server",
|
2023-02-14 05:02:16 -07:00
|
|
|
level=logger_level,
|
|
|
|
serialize=json_output,
|
|
|
|
backtrace=True,
|
|
|
|
diagnose=False,
|
|
|
|
)
|
|
|
|
|
2023-04-16 16:26:47 -06:00
|
|
|
# Import here after the logger is added to log potential import exceptions
|
|
|
|
from text_generation_server import utils
|
|
|
|
|
2023-02-14 05:02:16 -07:00
|
|
|
# Test if files were already download
|
|
|
|
try:
|
|
|
|
utils.weight_files(model_id, revision, extension)
|
2023-05-03 03:36:24 -06:00
|
|
|
logger.info("Files are already present on the host. " "Skipping download.")
|
2023-02-14 05:02:16 -07:00
|
|
|
return
|
|
|
|
# Local files not found
|
2023-12-11 04:46:30 -07:00
|
|
|
except (utils.LocalEntryNotFoundError, FileNotFoundError, utils.EntryNotFoundError):
|
2023-02-14 05:02:16 -07:00
|
|
|
pass
|
|
|
|
|
2023-05-03 03:36:24 -06:00
|
|
|
is_local_model = (Path(model_id).exists() and Path(model_id).is_dir()) or os.getenv(
|
|
|
|
"WEIGHTS_CACHE_OVERRIDE", None
|
|
|
|
) is not None
|
|
|
|
|
|
|
|
if not is_local_model:
|
2024-06-25 12:46:27 -06:00
|
|
|
# TODO: maybe reverse the default value of merge_lora?
|
|
|
|
# currently by default we don't merge the weights with the base model
|
|
|
|
if merge_lora:
|
|
|
|
try:
|
2024-07-26 08:29:09 -06:00
|
|
|
hf_hub_download(
|
2024-06-25 12:46:27 -06:00
|
|
|
model_id, revision=revision, filename="adapter_config.json"
|
|
|
|
)
|
|
|
|
utils.download_and_unload_peft(
|
|
|
|
model_id, revision, trust_remote_code=trust_remote_code
|
|
|
|
)
|
|
|
|
is_local_model = True
|
|
|
|
utils.weight_files(model_id, revision, extension)
|
|
|
|
return
|
|
|
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
utils.peft.download_peft(
|
|
|
|
model_id, revision, trust_remote_code=trust_remote_code
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
pass
|
feat(server): Add native support for PEFT Lora models (#762)
- Will detect `peft` model by finding `adapter_config.json`.
- This triggers a totally dedicated `download-weights` path
- This path, loads the adapter config, finds the base model_id
- It loads the base_model
- Then peft_model
- Then `merge_and_unload()`
- Then `save_pretrained(.., safe_serialization=True)
- Add back the config + tokenizer.merge_and_unload()`
- Then `save_pretrained(.., safe_serialization=True)
- Add back the config + tokenizer.
- The chosen location is a **local folder with the name of the user
chosen model id**
PROs:
- Easier than to expect user to merge manually
- Barely any change outside of `download-weights` command.
- This means everything will work in a single load.
- Should enable out of the box SM + HFE
CONs:
- Creates a local merged model in unusual location, potentially
not saved across docker reloads, or ovewriting some files if the PEFT
itself was local and containing other files in addition to the lora
Alternatives considered:
- Add `local_files_only=True` every where (discard because of massive
code change for not a good enough reason)
- Return something to `launcher` about the new model-id (a cleaner
location for this new model), but it would
introduce new communication somewhere where we didn't need it before.
- Using the HF cache folder and *stopping* the flow after
`download-weights` and asking user to restart with the actual local
model location
Fix #482
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2023-08-03 09:22:45 -06:00
|
|
|
|
2023-12-11 04:46:30 -07:00
|
|
|
try:
|
|
|
|
import json
|
2023-12-11 06:49:52 -07:00
|
|
|
|
2024-05-18 05:31:24 -06:00
|
|
|
config = hf_hub_download(
|
2023-12-11 06:49:52 -07:00
|
|
|
model_id, revision=revision, filename="config.json"
|
|
|
|
)
|
2024-05-18 05:31:24 -06:00
|
|
|
with open(config, "r") as f:
|
2023-12-11 04:46:30 -07:00
|
|
|
config = json.load(f)
|
|
|
|
|
2024-05-18 05:31:24 -06:00
|
|
|
base_model_id = config.get("base_model_name_or_path", None)
|
|
|
|
if base_model_id and base_model_id != model_id:
|
|
|
|
try:
|
|
|
|
logger.info(f"Downloading parent model {base_model_id}")
|
|
|
|
download_weights(
|
|
|
|
model_id=base_model_id,
|
|
|
|
revision="main",
|
|
|
|
extension=extension,
|
|
|
|
auto_convert=auto_convert,
|
|
|
|
logger_level=logger_level,
|
|
|
|
json_output=json_output,
|
|
|
|
trust_remote_code=trust_remote_code,
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
pass
|
2023-12-11 04:46:30 -07:00
|
|
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
|
|
|
pass
|
|
|
|
|
2023-05-03 03:36:24 -06:00
|
|
|
# Try to download weights from the hub
|
|
|
|
try:
|
|
|
|
filenames = utils.weight_hub_files(model_id, revision, extension)
|
|
|
|
utils.download_weights(filenames, model_id, revision)
|
|
|
|
# Successfully downloaded weights
|
|
|
|
return
|
|
|
|
|
|
|
|
# No weights found on the hub with this extension
|
|
|
|
except utils.EntryNotFoundError as e:
|
|
|
|
# Check if we want to automatically convert to safetensors or if we can use .bin weights instead
|
|
|
|
if not extension == ".safetensors" or not auto_convert:
|
|
|
|
raise e
|
|
|
|
|
2024-01-09 07:21:00 -07:00
|
|
|
elif (Path(model_id) / "adapter_config.json").exists():
|
Load PEFT weights from local directory (#1260)
# What does this PR do?
Enables PEFT weights to be loaded from a local directory, as opposed to
a hf hub repository. It is a continuation of the work in PR
https://github.com/huggingface/text-generation-inference/pull/762
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes #1259
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [x] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section? **Yes but I don't know how to run the tests for
this repo, and it doesn't look like this code is covered anyway**
- [x] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case. **Yes, @Narsil asked for a PR in [this
comment](https://github.com/huggingface/text-generation-inference/pull/762#issuecomment-1728089505)**
- [x] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
**I didn't see any documentation added to the [original
PR](https://github.com/huggingface/text-generation-inference/pull/762),
and am not sure where this belongs. Let me know and I can add some**
- [x] Did you write any new necessary tests? **I didn't see any existing
test coverage for this python module**
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
@Narsil
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@Narsil
-->
---------
Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
2023-11-23 04:56:17 -07:00
|
|
|
# Try to load as a local PEFT model
|
|
|
|
try:
|
|
|
|
utils.download_and_unload_peft(
|
|
|
|
model_id, revision, trust_remote_code=trust_remote_code
|
|
|
|
)
|
|
|
|
utils.weight_files(model_id, revision, extension)
|
|
|
|
return
|
|
|
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
|
|
|
pass
|
2024-05-18 05:31:24 -06:00
|
|
|
elif (Path(model_id) / "config.json").exists():
|
|
|
|
# Try to load as a local Medusa model
|
|
|
|
try:
|
|
|
|
import json
|
|
|
|
|
|
|
|
config = Path(model_id) / "config.json"
|
|
|
|
with open(config, "r") as f:
|
|
|
|
config = json.load(f)
|
|
|
|
|
|
|
|
base_model_id = config.get("base_model_name_or_path", None)
|
|
|
|
if base_model_id:
|
|
|
|
try:
|
|
|
|
logger.info(f"Downloading parent model {base_model_id}")
|
|
|
|
download_weights(
|
|
|
|
model_id=base_model_id,
|
|
|
|
revision="main",
|
|
|
|
extension=extension,
|
|
|
|
auto_convert=auto_convert,
|
|
|
|
logger_level=logger_level,
|
|
|
|
json_output=json_output,
|
|
|
|
trust_remote_code=trust_remote_code,
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
|
|
|
pass
|
Load PEFT weights from local directory (#1260)
# What does this PR do?
Enables PEFT weights to be loaded from a local directory, as opposed to
a hf hub repository. It is a continuation of the work in PR
https://github.com/huggingface/text-generation-inference/pull/762
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes #1259
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [x] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section? **Yes but I don't know how to run the tests for
this repo, and it doesn't look like this code is covered anyway**
- [x] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case. **Yes, @Narsil asked for a PR in [this
comment](https://github.com/huggingface/text-generation-inference/pull/762#issuecomment-1728089505)**
- [x] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
**I didn't see any documentation added to the [original
PR](https://github.com/huggingface/text-generation-inference/pull/762),
and am not sure where this belongs. Let me know and I can add some**
- [x] Did you write any new necessary tests? **I didn't see any existing
test coverage for this python module**
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
@Narsil
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@Narsil
-->
---------
Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
2023-11-23 04:56:17 -07:00
|
|
|
|
2023-05-03 03:36:24 -06:00
|
|
|
# Try to see if there are local pytorch weights
|
2023-02-14 05:02:16 -07:00
|
|
|
try:
|
2023-05-03 03:36:24 -06:00
|
|
|
# Get weights for a local model, a hub cached model and inside the WEIGHTS_CACHE_OVERRIDE
|
2024-05-18 05:31:24 -06:00
|
|
|
try:
|
|
|
|
local_pt_files = utils.weight_files(model_id, revision, ".bin")
|
|
|
|
except Exception:
|
|
|
|
local_pt_files = utils.weight_files(model_id, revision, ".pt")
|
2023-02-14 05:02:16 -07:00
|
|
|
|
2023-05-03 03:36:24 -06:00
|
|
|
# No local pytorch weights
|
2024-05-18 05:31:24 -06:00
|
|
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
2023-05-03 03:36:24 -06:00
|
|
|
if extension == ".safetensors":
|
|
|
|
logger.warning(
|
|
|
|
f"No safetensors weights found for model {model_id} at revision {revision}. "
|
|
|
|
f"Downloading PyTorch weights."
|
|
|
|
)
|
2023-02-14 05:02:16 -07:00
|
|
|
|
2023-05-03 03:36:24 -06:00
|
|
|
# Try to see if there are pytorch weights on the hub
|
2023-02-14 05:02:16 -07:00
|
|
|
pt_filenames = utils.weight_hub_files(model_id, revision, ".bin")
|
|
|
|
# Download pytorch weights
|
|
|
|
local_pt_files = utils.download_weights(pt_filenames, model_id, revision)
|
2023-05-03 03:36:24 -06:00
|
|
|
|
|
|
|
if auto_convert:
|
2024-04-05 05:32:53 -06:00
|
|
|
if not trust_remote_code:
|
|
|
|
logger.warning(
|
2024-07-26 08:29:09 -06:00
|
|
|
"🚨🚨BREAKING CHANGE in 2.0🚨🚨: Safetensors conversion is disabled without `--trust-remote-code` because "
|
|
|
|
"Pickle files are unsafe and can essentially contain remote code execution!"
|
|
|
|
"Please check for more information here: https://huggingface.co/docs/text-generation-inference/basic_tutorials/safety",
|
2024-04-05 05:32:53 -06:00
|
|
|
)
|
|
|
|
|
2023-05-03 03:36:24 -06:00
|
|
|
logger.warning(
|
|
|
|
f"No safetensors weights found for model {model_id} at revision {revision}. "
|
|
|
|
f"Converting PyTorch weights to safetensors."
|
|
|
|
)
|
|
|
|
|
|
|
|
# Safetensors final filenames
|
2023-02-14 05:02:16 -07:00
|
|
|
local_st_files = [
|
|
|
|
p.parent / f"{p.stem.lstrip('pytorch_')}.safetensors"
|
|
|
|
for p in local_pt_files
|
|
|
|
]
|
2023-07-07 06:50:12 -06:00
|
|
|
try:
|
|
|
|
import transformers
|
2023-08-11 08:46:08 -06:00
|
|
|
import json
|
2023-07-07 06:50:12 -06:00
|
|
|
|
support local model config file (#1058)
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Support local config file to avoid unexpected `discard_names`, which
causes #1057.
In the case of launching local mode without `model.safetensors` file,
the original code will result `discard_names = []` when
`hf_hub_download` throws an connection error.
```python
# server/text_generation_server/cli.py
try:
import transformers
import json
config_filename = hf_hub_download(model_id, revision=revision, filename="config.json")
with open(config_filename, "r") as f:
config = json.load(f)
architecture = config["architectures"][0]
class_ = getattr(transformers, architecture)
# Name for this varible depends on transformers version.
discard_names = getattr(class_, "_tied_weights_keys", [])
discard_names.extend(getattr(class_, "_keys_to_ignore_on_load_missing", []))
except Exception as e:
discard_names = []
```
The expected `_tied_weights_keys` of OPT-1.3b is `["lm_head.weight"]`,
and its tied weight `"model.decoder.embed_tokens.weight"` will be kept
in the safetensors conversion. But the above empty `discard_names` will
lead to `"lm_head.weight"` being kept and
`"model.decoder.embed_tokens.weight"` being discard in the subsequent
method `_remove_duplicate_names`, which causes error #1057.
So add a local mode branch to get the expected `discard_names` like
follows. This modification also applies to other models
```python
# server/text_generation_server/cli.py
if is_local_model:
config_filename = os.path.join(model_id, "config.json")
else:
config_filename = hf_hub_download(model_id, revision=revision, filename="config.json")
```
In addition, when `_tied_weights_keys` or
`_keys_to_ignore_on_load_missing` is `None`, the above code will also
throw an error unexpectedly. This is fixed in PR #1052
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [x] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [x] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
N/A
- [ ] Did you write any new necessary tests? N/A
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
@Narsil
2023-09-26 06:57:53 -06:00
|
|
|
if is_local_model:
|
|
|
|
config_filename = os.path.join(model_id, "config.json")
|
|
|
|
else:
|
2023-09-27 04:22:09 -06:00
|
|
|
config_filename = hf_hub_download(
|
|
|
|
model_id, revision=revision, filename="config.json"
|
|
|
|
)
|
2023-08-11 08:46:08 -06:00
|
|
|
with open(config_filename, "r") as f:
|
|
|
|
config = json.load(f)
|
|
|
|
architecture = config["architectures"][0]
|
2023-07-07 06:50:12 -06:00
|
|
|
|
|
|
|
class_ = getattr(transformers, architecture)
|
|
|
|
|
|
|
|
# Name for this varible depends on transformers version.
|
|
|
|
discard_names = getattr(class_, "_tied_weights_keys", [])
|
|
|
|
|
2024-07-26 08:29:09 -06:00
|
|
|
except Exception:
|
2023-07-07 06:50:12 -06:00
|
|
|
discard_names = []
|
2023-02-14 05:02:16 -07:00
|
|
|
# Convert pytorch weights to safetensors
|
2023-07-07 06:50:12 -06:00
|
|
|
utils.convert_files(local_pt_files, local_st_files, discard_names)
|
2022-10-17 06:59:00 -06:00
|
|
|
|
|
|
|
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
@app.command()
|
|
|
|
def quantize(
|
|
|
|
model_id: str,
|
|
|
|
output_dir: str,
|
|
|
|
revision: Optional[str] = None,
|
|
|
|
logger_level: str = "INFO",
|
|
|
|
json_output: bool = False,
|
|
|
|
trust_remote_code: bool = False,
|
|
|
|
upload_to_model_id: Optional[str] = None,
|
|
|
|
percdamp: float = 0.01,
|
|
|
|
act_order: bool = False,
|
2024-07-16 00:36:05 -06:00
|
|
|
groupsize: int = 128,
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
):
|
2023-07-18 04:19:05 -06:00
|
|
|
if revision is None:
|
|
|
|
revision = "main"
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
download_weights(
|
|
|
|
model_id=model_id,
|
|
|
|
revision=revision,
|
|
|
|
logger_level=logger_level,
|
|
|
|
json_output=json_output,
|
|
|
|
)
|
2024-06-21 07:28:51 -06:00
|
|
|
from text_generation_server.layers.gptq.quantize import quantize
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
|
|
|
|
quantize(
|
|
|
|
model_id=model_id,
|
|
|
|
bits=4,
|
2024-07-16 00:36:05 -06:00
|
|
|
groupsize=groupsize,
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
output_dir=output_dir,
|
2023-07-18 04:19:05 -06:00
|
|
|
revision=revision,
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
trust_remote_code=trust_remote_code,
|
|
|
|
upload_to_model_id=upload_to_model_id,
|
|
|
|
percdamp=percdamp,
|
|
|
|
act_order=act_order,
|
2024-07-12 04:20:12 -06:00
|
|
|
sym=True,
|
feat(server): Add inference support for GPTQ (llama + falcon tested) + Quantization script (#438)
Let's start discussing implementation.
- Need to expose the quantization scripts (either included here or add
doc on how to use https://github.com/qwopqwop200/GPTQ-for-LLaMa)
- Make sure GPTQ works for multiple models (priority to Falcon).
Currently it means that every place we use `get_{tensor|sharded}` to
check for quantization.
My idea is to reintegrate as much as possible into `utils/layer.py` by
expanding `load_multi` to be a bit more generic.
This might require some thinking, but ultimately the
`qweight,qzeros,scales,g_idx` should be in a single place, and
independant of bias presence.
# What does this PR do?
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
---------
Co-authored-by: Ubuntu <ubuntu@ip-172-31-41-161.ec2.internal>
Co-authored-by: OlivierDehaene <olivier@huggingface.co>
2023-06-26 04:27:01 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-10-17 06:59:00 -06:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app()
|