2023-06-16 18:00:37 -04:00
|
|
|
import functools
|
2023-08-11 13:41:33 -04:00
|
|
|
from collections import OrderedDict
|
2023-06-16 18:00:37 -04:00
|
|
|
|
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
from modules import shared
|
|
|
|
|
2023-08-11 13:41:33 -04:00
|
|
|
loaders_and_params = OrderedDict({
|
|
|
|
'Transformers': [
|
|
|
|
'cpu_memory',
|
|
|
|
'gpu_memory',
|
|
|
|
'load_in_8bit',
|
|
|
|
'bf16',
|
|
|
|
'cpu',
|
|
|
|
'disk',
|
|
|
|
'auto_devices',
|
|
|
|
'load_in_4bit',
|
|
|
|
'use_double_quant',
|
|
|
|
'quant_type',
|
|
|
|
'compute_dtype',
|
|
|
|
'trust_remote_code',
|
2023-11-16 22:45:05 -05:00
|
|
|
'no_use_fast',
|
2023-11-04 12:59:33 -04:00
|
|
|
'use_flash_attention_2',
|
2023-08-11 13:41:33 -04:00
|
|
|
'alpha_value',
|
2023-08-25 09:53:37 -04:00
|
|
|
'rope_freq_base',
|
2023-08-11 13:41:33 -04:00
|
|
|
'compress_pos_emb',
|
2023-09-24 23:03:11 -04:00
|
|
|
'disable_exllama',
|
2023-12-15 09:46:13 -05:00
|
|
|
'disable_exllamav2',
|
2024-02-04 22:13:34 -05:00
|
|
|
'transformers_info',
|
2023-08-11 13:41:33 -04:00
|
|
|
],
|
2023-11-29 18:13:03 -05:00
|
|
|
'llama.cpp': [
|
|
|
|
'n_ctx',
|
|
|
|
'n_gpu_layers',
|
|
|
|
'tensor_split',
|
|
|
|
'n_batch',
|
|
|
|
'threads',
|
|
|
|
'threads_batch',
|
|
|
|
'no_mmap',
|
|
|
|
'mlock',
|
|
|
|
'no_mul_mat_q',
|
|
|
|
'alpha_value',
|
|
|
|
'rope_freq_base',
|
|
|
|
'compress_pos_emb',
|
2024-04-30 08:11:31 -04:00
|
|
|
'cpu',
|
2023-11-29 18:13:03 -05:00
|
|
|
'numa',
|
2023-12-19 15:30:53 -05:00
|
|
|
'no_offload_kqv',
|
2024-02-04 21:36:40 -05:00
|
|
|
'row_split',
|
2024-04-30 08:11:31 -04:00
|
|
|
'tensorcores',
|
2024-05-03 07:31:22 -04:00
|
|
|
'flash-attn',
|
2024-03-08 22:25:33 -05:00
|
|
|
'streaming_llm',
|
|
|
|
'attention_sink_size',
|
2023-11-29 18:13:03 -05:00
|
|
|
],
|
2023-11-28 21:41:11 -05:00
|
|
|
'llamacpp_HF': [
|
|
|
|
'n_ctx',
|
|
|
|
'n_gpu_layers',
|
|
|
|
'tensor_split',
|
|
|
|
'n_batch',
|
|
|
|
'threads',
|
|
|
|
'threads_batch',
|
|
|
|
'no_mmap',
|
|
|
|
'mlock',
|
|
|
|
'no_mul_mat_q',
|
|
|
|
'alpha_value',
|
|
|
|
'rope_freq_base',
|
|
|
|
'compress_pos_emb',
|
2024-04-30 08:11:31 -04:00
|
|
|
'cpu',
|
2023-11-28 21:41:11 -05:00
|
|
|
'numa',
|
|
|
|
'cfg_cache',
|
2023-12-08 09:29:26 -05:00
|
|
|
'trust_remote_code',
|
2023-11-28 21:41:11 -05:00
|
|
|
'no_use_fast',
|
|
|
|
'logits_all',
|
2023-12-19 13:22:21 -05:00
|
|
|
'no_offload_kqv',
|
2024-02-04 21:36:40 -05:00
|
|
|
'row_split',
|
2024-04-30 08:11:31 -04:00
|
|
|
'tensorcores',
|
2024-05-03 07:31:22 -04:00
|
|
|
'flash-attn',
|
2024-03-08 22:25:33 -05:00
|
|
|
'streaming_llm',
|
|
|
|
'attention_sink_size',
|
2023-11-28 21:41:11 -05:00
|
|
|
'llamacpp_HF_info',
|
|
|
|
],
|
2023-12-17 10:08:33 -05:00
|
|
|
'ExLlamav2_HF': [
|
2023-08-11 13:41:33 -04:00
|
|
|
'gpu_split',
|
|
|
|
'max_seq_len',
|
2023-12-17 10:08:33 -05:00
|
|
|
'cfg_cache',
|
|
|
|
'no_flash_attn',
|
|
|
|
'num_experts_per_token',
|
|
|
|
'cache_8bit',
|
2024-03-06 21:02:25 -05:00
|
|
|
'cache_4bit',
|
2024-02-16 13:26:10 -05:00
|
|
|
'autosplit',
|
2023-08-11 13:41:33 -04:00
|
|
|
'alpha_value',
|
|
|
|
'compress_pos_emb',
|
2023-12-08 09:29:26 -05:00
|
|
|
'trust_remote_code',
|
2023-11-16 22:45:05 -05:00
|
|
|
'no_use_fast',
|
2023-08-11 13:41:33 -04:00
|
|
|
],
|
2024-02-06 09:21:17 -05:00
|
|
|
'ExLlamav2': [
|
|
|
|
'gpu_split',
|
|
|
|
'max_seq_len',
|
|
|
|
'no_flash_attn',
|
|
|
|
'num_experts_per_token',
|
|
|
|
'cache_8bit',
|
2024-03-06 21:02:25 -05:00
|
|
|
'cache_4bit',
|
2024-02-16 13:26:10 -05:00
|
|
|
'autosplit',
|
2024-02-06 09:21:17 -05:00
|
|
|
'alpha_value',
|
|
|
|
'compress_pos_emb',
|
|
|
|
'exllamav2_info',
|
|
|
|
],
|
2023-06-16 18:00:37 -04:00
|
|
|
'AutoGPTQ': [
|
|
|
|
'triton',
|
|
|
|
'no_inject_fused_mlp',
|
2023-06-23 11:22:56 -04:00
|
|
|
'no_use_cuda_fp16',
|
2023-06-16 18:00:37 -04:00
|
|
|
'wbits',
|
|
|
|
'groupsize',
|
|
|
|
'desc_act',
|
2023-08-12 02:26:58 -04:00
|
|
|
'disable_exllama',
|
2023-12-15 09:46:13 -05:00
|
|
|
'disable_exllamav2',
|
2023-06-16 18:00:37 -04:00
|
|
|
'gpu_memory',
|
|
|
|
'cpu_memory',
|
|
|
|
'cpu',
|
|
|
|
'disk',
|
|
|
|
'auto_devices',
|
|
|
|
'trust_remote_code',
|
2023-11-16 22:45:05 -05:00
|
|
|
'no_use_fast',
|
2023-06-16 18:00:37 -04:00
|
|
|
'autogptq_info',
|
|
|
|
],
|
2023-11-28 21:43:33 -05:00
|
|
|
'AutoAWQ': [
|
|
|
|
'cpu_memory',
|
|
|
|
'gpu_memory',
|
|
|
|
'auto_devices',
|
|
|
|
'max_seq_len',
|
|
|
|
'no_inject_fused_attention',
|
|
|
|
'trust_remote_code',
|
|
|
|
'no_use_fast',
|
|
|
|
],
|
2023-12-18 19:23:16 -05:00
|
|
|
'HQQ': [
|
|
|
|
'hqq_backend',
|
|
|
|
'trust_remote_code',
|
|
|
|
'no_use_fast',
|
2023-12-05 22:01:01 -05:00
|
|
|
]
|
2023-08-11 13:41:33 -04:00
|
|
|
})
|
2023-06-16 18:00:37 -04:00
|
|
|
|
2023-12-20 22:18:07 -05:00
|
|
|
|
|
|
|
def transformers_samplers():
|
|
|
|
return {
|
2023-07-31 21:44:00 -04:00
|
|
|
'temperature',
|
2023-11-04 12:09:07 -04:00
|
|
|
'temperature_last',
|
2024-01-07 15:03:47 -05:00
|
|
|
'dynamic_temperature',
|
2024-01-08 21:28:35 -05:00
|
|
|
'dynatemp_low',
|
|
|
|
'dynatemp_high',
|
|
|
|
'dynatemp_exponent',
|
2024-02-03 22:20:02 -05:00
|
|
|
'smoothing_factor',
|
2024-03-03 11:22:21 -05:00
|
|
|
'smoothing_curve',
|
2023-07-31 21:44:00 -04:00
|
|
|
'top_p',
|
2023-11-02 15:32:51 -04:00
|
|
|
'min_p',
|
2023-07-31 21:44:00 -04:00
|
|
|
'top_k',
|
|
|
|
'typical_p',
|
|
|
|
'epsilon_cutoff',
|
|
|
|
'eta_cutoff',
|
|
|
|
'tfs',
|
|
|
|
'top_a',
|
|
|
|
'repetition_penalty',
|
2023-10-25 11:10:28 -04:00
|
|
|
'presence_penalty',
|
|
|
|
'frequency_penalty',
|
2023-07-31 21:44:00 -04:00
|
|
|
'repetition_penalty_range',
|
|
|
|
'encoder_repetition_penalty',
|
|
|
|
'no_repeat_ngram_size',
|
2024-05-19 22:53:47 -04:00
|
|
|
'dry_multiplier',
|
|
|
|
'dry_base',
|
|
|
|
'dry_allowed_length',
|
|
|
|
'dry_sequence_breakers',
|
2023-07-31 21:44:00 -04:00
|
|
|
'seed',
|
|
|
|
'do_sample',
|
|
|
|
'penalty_alpha',
|
|
|
|
'mirostat_mode',
|
|
|
|
'mirostat_tau',
|
|
|
|
'mirostat_eta',
|
2023-10-05 09:01:36 -04:00
|
|
|
'grammar_file_row',
|
|
|
|
'grammar_string',
|
2023-08-06 16:22:48 -04:00
|
|
|
'guidance_scale',
|
|
|
|
'negative_prompt',
|
2023-07-31 21:44:00 -04:00
|
|
|
'ban_eos_token',
|
2023-09-15 17:27:27 -04:00
|
|
|
'custom_token_bans',
|
2024-02-06 09:20:10 -05:00
|
|
|
'sampler_priority',
|
2023-07-31 21:44:00 -04:00
|
|
|
'add_bos_token',
|
|
|
|
'skip_special_tokens',
|
2023-08-02 13:52:20 -04:00
|
|
|
'auto_max_new_tokens',
|
2024-01-17 15:09:36 -05:00
|
|
|
'prompt_lookup_num_tokens'
|
2023-12-20 22:18:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loaders_samplers = {
|
|
|
|
'Transformers': transformers_samplers(),
|
|
|
|
'AutoGPTQ': transformers_samplers(),
|
|
|
|
'AutoAWQ': transformers_samplers(),
|
|
|
|
'HQQ': transformers_samplers(),
|
2024-02-06 09:21:17 -05:00
|
|
|
'ExLlamav2': {
|
|
|
|
'temperature',
|
|
|
|
'temperature_last',
|
|
|
|
'top_p',
|
|
|
|
'min_p',
|
|
|
|
'top_k',
|
|
|
|
'typical_p',
|
|
|
|
'tfs',
|
|
|
|
'top_a',
|
|
|
|
'repetition_penalty',
|
|
|
|
'presence_penalty',
|
|
|
|
'frequency_penalty',
|
|
|
|
'repetition_penalty_range',
|
|
|
|
'seed',
|
|
|
|
'mirostat_mode',
|
|
|
|
'mirostat_tau',
|
|
|
|
'mirostat_eta',
|
|
|
|
'ban_eos_token',
|
|
|
|
'add_bos_token',
|
|
|
|
'custom_token_bans',
|
|
|
|
'skip_special_tokens',
|
|
|
|
'auto_max_new_tokens',
|
|
|
|
},
|
2023-09-12 13:33:07 -04:00
|
|
|
'ExLlamav2_HF': {
|
|
|
|
'temperature',
|
2023-11-04 12:09:07 -04:00
|
|
|
'temperature_last',
|
2024-01-07 15:03:47 -05:00
|
|
|
'dynamic_temperature',
|
2024-01-08 21:28:35 -05:00
|
|
|
'dynatemp_low',
|
|
|
|
'dynatemp_high',
|
|
|
|
'dynatemp_exponent',
|
2024-02-03 22:20:02 -05:00
|
|
|
'smoothing_factor',
|
2024-03-03 11:22:21 -05:00
|
|
|
'smoothing_curve',
|
2023-09-12 13:33:07 -04:00
|
|
|
'top_p',
|
2023-11-02 15:32:51 -04:00
|
|
|
'min_p',
|
2023-09-12 13:33:07 -04:00
|
|
|
'top_k',
|
|
|
|
'typical_p',
|
|
|
|
'epsilon_cutoff',
|
|
|
|
'eta_cutoff',
|
|
|
|
'tfs',
|
|
|
|
'top_a',
|
|
|
|
'repetition_penalty',
|
2023-10-25 11:10:28 -04:00
|
|
|
'presence_penalty',
|
|
|
|
'frequency_penalty',
|
2023-09-12 13:33:07 -04:00
|
|
|
'repetition_penalty_range',
|
|
|
|
'encoder_repetition_penalty',
|
|
|
|
'no_repeat_ngram_size',
|
2024-05-19 22:53:47 -04:00
|
|
|
'dry_multiplier',
|
|
|
|
'dry_base',
|
|
|
|
'dry_allowed_length',
|
|
|
|
'dry_sequence_breakers',
|
2023-09-12 13:33:07 -04:00
|
|
|
'seed',
|
|
|
|
'do_sample',
|
|
|
|
'mirostat_mode',
|
|
|
|
'mirostat_tau',
|
|
|
|
'mirostat_eta',
|
2023-10-05 09:01:36 -04:00
|
|
|
'grammar_file_row',
|
|
|
|
'grammar_string',
|
2023-09-12 13:33:07 -04:00
|
|
|
'guidance_scale',
|
|
|
|
'negative_prompt',
|
|
|
|
'ban_eos_token',
|
2023-09-15 17:27:27 -04:00
|
|
|
'custom_token_bans',
|
2024-02-06 09:20:10 -05:00
|
|
|
'sampler_priority',
|
2023-09-12 13:33:07 -04:00
|
|
|
'add_bos_token',
|
|
|
|
'skip_special_tokens',
|
|
|
|
'auto_max_new_tokens',
|
|
|
|
},
|
2023-07-31 21:44:00 -04:00
|
|
|
'llama.cpp': {
|
|
|
|
'temperature',
|
|
|
|
'top_p',
|
2023-11-21 18:59:39 -05:00
|
|
|
'min_p',
|
2023-07-31 21:44:00 -04:00
|
|
|
'top_k',
|
2023-11-21 18:59:39 -05:00
|
|
|
'typical_p',
|
2023-07-31 21:44:00 -04:00
|
|
|
'tfs',
|
|
|
|
'repetition_penalty',
|
2023-10-25 11:10:28 -04:00
|
|
|
'presence_penalty',
|
|
|
|
'frequency_penalty',
|
2023-11-17 22:31:27 -05:00
|
|
|
'seed',
|
2023-07-31 21:44:00 -04:00
|
|
|
'mirostat_mode',
|
|
|
|
'mirostat_tau',
|
|
|
|
'mirostat_eta',
|
2023-09-24 10:17:33 -04:00
|
|
|
'grammar_file_row',
|
2023-09-24 17:05:24 -04:00
|
|
|
'grammar_string',
|
2023-07-31 21:44:00 -04:00
|
|
|
'ban_eos_token',
|
2023-09-15 17:27:27 -04:00
|
|
|
'custom_token_bans',
|
2023-07-31 21:44:00 -04:00
|
|
|
},
|
|
|
|
'llamacpp_HF': {
|
|
|
|
'temperature',
|
2023-11-04 12:09:07 -04:00
|
|
|
'temperature_last',
|
2024-01-07 15:03:47 -05:00
|
|
|
'dynamic_temperature',
|
2024-01-08 21:28:35 -05:00
|
|
|
'dynatemp_low',
|
|
|
|
'dynatemp_high',
|
|
|
|
'dynatemp_exponent',
|
2024-02-03 22:20:02 -05:00
|
|
|
'smoothing_factor',
|
2024-03-03 11:22:21 -05:00
|
|
|
'smoothing_curve',
|
2023-07-31 21:44:00 -04:00
|
|
|
'top_p',
|
2023-11-02 15:32:51 -04:00
|
|
|
'min_p',
|
2023-07-31 21:44:00 -04:00
|
|
|
'top_k',
|
|
|
|
'typical_p',
|
|
|
|
'epsilon_cutoff',
|
|
|
|
'eta_cutoff',
|
|
|
|
'tfs',
|
|
|
|
'top_a',
|
|
|
|
'repetition_penalty',
|
2023-10-25 11:10:28 -04:00
|
|
|
'presence_penalty',
|
|
|
|
'frequency_penalty',
|
2023-07-31 21:44:00 -04:00
|
|
|
'repetition_penalty_range',
|
|
|
|
'encoder_repetition_penalty',
|
|
|
|
'no_repeat_ngram_size',
|
2024-05-19 22:53:47 -04:00
|
|
|
'dry_multiplier',
|
|
|
|
'dry_base',
|
|
|
|
'dry_allowed_length',
|
|
|
|
'dry_sequence_breakers',
|
2023-07-31 21:44:00 -04:00
|
|
|
'seed',
|
|
|
|
'do_sample',
|
|
|
|
'mirostat_mode',
|
|
|
|
'mirostat_tau',
|
|
|
|
'mirostat_eta',
|
2023-10-05 09:01:36 -04:00
|
|
|
'grammar_file_row',
|
|
|
|
'grammar_string',
|
2023-08-24 19:32:21 -04:00
|
|
|
'guidance_scale',
|
|
|
|
'negative_prompt',
|
2023-07-31 21:44:00 -04:00
|
|
|
'ban_eos_token',
|
2023-09-15 17:27:27 -04:00
|
|
|
'custom_token_bans',
|
2024-02-06 09:20:10 -05:00
|
|
|
'sampler_priority',
|
2023-07-31 21:44:00 -04:00
|
|
|
'add_bos_token',
|
|
|
|
'skip_special_tokens',
|
2023-08-02 13:52:20 -04:00
|
|
|
'auto_max_new_tokens',
|
2023-07-31 21:44:00 -04:00
|
|
|
},
|
2023-08-11 13:41:33 -04:00
|
|
|
}
|
|
|
|
|
2023-07-31 21:44:00 -04:00
|
|
|
|
|
|
|
@functools.cache
|
|
|
|
def list_all_samplers():
|
|
|
|
all_samplers = set()
|
|
|
|
for k in loaders_samplers:
|
|
|
|
for sampler in loaders_samplers[k]:
|
|
|
|
all_samplers.add(sampler)
|
|
|
|
|
|
|
|
return sorted(all_samplers)
|
|
|
|
|
|
|
|
|
2024-01-08 22:42:31 -05:00
|
|
|
def blacklist_samplers(loader, dynamic_temperature):
|
2023-07-31 21:44:00 -04:00
|
|
|
all_samplers = list_all_samplers()
|
2024-01-08 22:42:31 -05:00
|
|
|
output = []
|
|
|
|
|
|
|
|
for sampler in all_samplers:
|
|
|
|
if loader == 'All' or sampler in loaders_samplers[loader]:
|
|
|
|
if sampler.startswith('dynatemp'):
|
|
|
|
output.append(gr.update(visible=dynamic_temperature))
|
|
|
|
else:
|
|
|
|
output.append(gr.update(visible=True))
|
|
|
|
else:
|
|
|
|
output.append(gr.update(visible=False))
|
|
|
|
|
|
|
|
return output
|
2023-07-31 21:44:00 -04:00
|
|
|
|
2023-06-16 18:00:37 -04:00
|
|
|
|
|
|
|
def get_gpu_memory_keys():
|
|
|
|
return [k for k in shared.gradio if k.startswith('gpu_memory')]
|
|
|
|
|
|
|
|
|
|
|
|
@functools.cache
|
|
|
|
def get_all_params():
|
|
|
|
all_params = set()
|
|
|
|
for k in loaders_and_params:
|
|
|
|
for el in loaders_and_params[k]:
|
|
|
|
all_params.add(el)
|
|
|
|
|
|
|
|
if 'gpu_memory' in all_params:
|
|
|
|
all_params.remove('gpu_memory')
|
|
|
|
for k in get_gpu_memory_keys():
|
|
|
|
all_params.add(k)
|
|
|
|
|
|
|
|
return sorted(all_params)
|
|
|
|
|
|
|
|
|
|
|
|
def make_loader_params_visible(loader):
|
|
|
|
params = []
|
|
|
|
all_params = get_all_params()
|
|
|
|
if loader in loaders_and_params:
|
|
|
|
params = loaders_and_params[loader]
|
|
|
|
|
|
|
|
if 'gpu_memory' in params:
|
|
|
|
params.remove('gpu_memory')
|
|
|
|
params += get_gpu_memory_keys()
|
|
|
|
|
|
|
|
return [gr.update(visible=True) if k in params else gr.update(visible=False) for k in all_params]
|