Add cache_4bit option for ExLlamaV2 (#5645)

This commit is contained in:
oobabooga 2024-03-06 23:02:25 -03:00 committed by GitHub
parent fa0e68cefd
commit 2ec1d96c91
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 28 additions and 16 deletions

View file

@ -6,6 +6,7 @@ from exllamav2 import (
ExLlamaV2,
ExLlamaV2Cache,
ExLlamaV2Cache_8bit,
ExLlamaV2Cache_Q4,
ExLlamaV2Config,
ExLlamaV2Tokenizer
)
@ -60,6 +61,8 @@ class Exllamav2Model:
if shared.args.cache_8bit:
cache = ExLlamaV2Cache_8bit(model, lazy=shared.args.autosplit)
elif shared.args.cache_4bit:
cache = ExLlamaV2Cache_Q4(model, lazy=shared.args.autosplit)
else:
cache = ExLlamaV2Cache(model, lazy=shared.args.autosplit)

View file

@ -8,6 +8,7 @@ from exllamav2 import (
ExLlamaV2,
ExLlamaV2Cache,
ExLlamaV2Cache_8bit,
ExLlamaV2Cache_Q4,
ExLlamaV2Config
)
from torch.nn import CrossEntropyLoss
@ -50,6 +51,8 @@ class Exllamav2HF(PreTrainedModel):
if shared.args.cache_8bit:
self.ex_cache = ExLlamaV2Cache_8bit(self.ex_model, lazy=shared.args.autosplit)
elif shared.args.cache_4bit:
self.ex_cache = ExLlamaV2Cache_Q4(self.ex_model, lazy=shared.args.autosplit)
else:
self.ex_cache = ExLlamaV2Cache(self.ex_model, lazy=shared.args.autosplit)

View file

@ -78,6 +78,7 @@ loaders_and_params = OrderedDict({
'no_flash_attn',
'num_experts_per_token',
'cache_8bit',
'cache_4bit',
'autosplit',
'alpha_value',
'compress_pos_emb',
@ -90,6 +91,7 @@ loaders_and_params = OrderedDict({
'no_flash_attn',
'num_experts_per_token',
'cache_8bit',
'cache_4bit',
'autosplit',
'alpha_value',
'compress_pos_emb',

View file

@ -139,6 +139,7 @@ group.add_argument('--max_seq_len', type=int, default=2048, help='Maximum sequen
group.add_argument('--cfg-cache', action='store_true', help='ExLlamav2_HF: Create an additional cache for CFG negative prompts. Necessary to use CFG with that loader.')
group.add_argument('--no_flash_attn', action='store_true', help='Force flash-attention to not be used.')
group.add_argument('--cache_8bit', action='store_true', help='Use 8-bit cache to save VRAM.')
group.add_argument('--cache_4bit', action='store_true', help='Use 4-bit cache to save VRAM.')
group.add_argument('--num_experts_per_token', type=int, default=2, help='Number of experts to use for generation. Applies to MoE models like Mixtral.')
# AutoGPTQ

View file

@ -76,6 +76,7 @@ def list_model_elements():
'no_flash_attn',
'num_experts_per_token',
'cache_8bit',
'cache_4bit',
'autosplit',
'threads',
'threads_batch',

View file

@ -132,6 +132,7 @@ def create_ui():
shared.gradio['disk'] = gr.Checkbox(label="disk", value=shared.args.disk)
shared.gradio['bf16'] = gr.Checkbox(label="bf16", value=shared.args.bf16)
shared.gradio['cache_8bit'] = gr.Checkbox(label="cache_8bit", value=shared.args.cache_8bit, info='Use 8-bit cache to save VRAM.')
shared.gradio['cache_4bit'] = gr.Checkbox(label="cache_4bit", value=shared.args.cache_4bit, info='Use 4-bit cache to save VRAM.')
shared.gradio['autosplit'] = gr.Checkbox(label="autosplit", value=shared.args.autosplit, info='Automatically split the model tensors across the available GPUs.')
shared.gradio['no_flash_attn'] = gr.Checkbox(label="no_flash_attn", value=shared.args.no_flash_attn, info='Force flash-attention to not be used.')
shared.gradio['cfg_cache'] = gr.Checkbox(label="cfg-cache", value=shared.args.cfg_cache, info='Necessary to use CFG with this loader.')