Skip to content

Commit

Permalink
Merge pull request #5220 from oobabooga/dev
Browse files Browse the repository at this point in the history
Merge dev branch
  • Loading branch information
oobabooga committed Jan 10, 2024
2 parents ad1ff53 + 038b4fc commit 2dc8db8
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 120 deletions.
21 changes: 16 additions & 5 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ button {
border: var(--input-border-width) solid var(--input-border-color) !important;
}

.file-saver > :first-child > :nth-child(2) {
.file-saver > :first-child > :last-child {
background: var(--block-background-fill);
justify-content: flex-end;
}

.checkboxgroup-table label {
Expand Down Expand Up @@ -652,14 +653,24 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
/* ----------------------------------------------
Past chats menus
---------------------------------------------- */
#past-chats-row {
margin-bottom: calc( -1 * var(--layout-gap) );
}

#rename-row label {
margin-top: var(--layout-gap);
}

/* ----------------------------------------------
Past chat histories in a side bar on desktop
---------------------------------------------- */
@media screen and (width >= 1327px) {
#past-chats-row {
position: absolute;
top: 16px;
left: 0;
width: calc(0.5*(var(--document-width) - 880px - 120px - 16px*2));
max-width: 300px;
margin-left: calc(-0.5*(var(--document-width) - 880px - 14px - 16px * 2));
}
}

/* ----------------------------------------------
Keep dropdown menus above errored components
---------------------------------------------- */
Expand Down
5 changes: 2 additions & 3 deletions docs/03 - Parameters Tab.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ These were obtained after a blind contest called "Preset Arena" where hundreds o

A key takeaway is that the best presets are:

* **For Instruct**: Divine Intellect, Big O, simple-1, Space Alien, StarChat, Titanic, tfs-with-top-a, Asterism, Contrastive Search (only works for the Transformers loader at the moment).
* **For Instruct**: Divine Intellect, Big O, simple-1.
* **For Chat**: Midnight Enigma, Yara, Shortwave.

The other presets are:
Expand Down Expand Up @@ -54,8 +54,7 @@ For more information about the parameters, the [transformers documentation](http
* **mirostat_mode**: Activates the Mirostat sampling technique. It aims to control perplexity during sampling. See the [paper](https://arxiv.org/abs/2007.14966).
* **mirostat_tau**: No idea, see the paper for details. According to the Preset Arena, 8 is a good value.
* **mirostat_eta**: No idea, see the paper for details. According to the Preset Arena, 0.1 is a good value.
* **dynamic_temperature_low**: The lower bound for temperature in Dynamic Temperature. Only used when "dynamic_temperature" is checked.
* **dynamic_temperature**: Activates Dynamic Temperature. This modifies temperature to range between "dynamic_temperature_low" (minimum) and "temperature" (maximum), with an entropy-based scaling.
* **dynamic_temperature**: Activates Dynamic Temperature. This modifies temperature to range between "dynatemp_low" (minimum) and "dynatemp_high" (maximum), with an entropy-based scaling. The steepness of the curve is controlled by "dynatemp_exponent".
* **temperature_last**: Makes temperature the last sampler instead of the first. With this, you can remove low probability tokens with a sampler like min_p and then use a high temperature to make the model creative without losing coherency.
* **do_sample**: When unchecked, sampling is entirely disabled, and greedy decoding is used instead (the most likely token is always picked).
* **Seed**: Set the Pytorch seed to this number. Note that some loaders do not use Pytorch (notably llama.cpp), and others are not deterministic (notably ExLlama v1 and v2). For these loaders, the seed has no effect.
Expand Down
2 changes: 1 addition & 1 deletion extensions/gallery/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def ui():
gr.HTML(value="<style>" + generate_css() + "</style>")
with gr.Row():
filter_box = gr.Textbox(label='', placeholder='Filter', lines=1, max_lines=1, container=False, elem_id='gallery-filter-box')
gr.ClearButton(filter_box, value='🗑️', elem_classes='refresh-button')
gr.ClearButton(filter_box, value='Clear', elem_classes='refresh-button')
update = gr.Button("Refresh", elem_classes='refresh-button')

gallery = gr.Dataset(
Expand Down
4 changes: 3 additions & 1 deletion extensions/openai/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class GenerationOptions(BaseModel):
preset: str | None = Field(default=None, description="The name of a file under text-generation-webui/presets (without the .yaml extension). The sampling parameters that get overwritten by this option are the keys in the default_preset() function in modules/presets.py.")
min_p: float = 0
dynamic_temperature: bool = False
dynamic_temperature_low: float = 0.1
dynatemp_low: float = 1
dynatemp_high: float = 1
dynatemp_exponent: float = 1
top_k: int = 0
repetition_penalty: float = 1
repetition_penalty_range: int = 1024
Expand Down
7 changes: 3 additions & 4 deletions instruction-templates/Mistral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ instruction_template: |-
{{- message['content'] -}}
{%- else -%}
{%- if message['role'] == 'user' -%}
{{-'[INST] ' + message['content'] + ' [/INST]'-}}
{{-' [INST] ' + message['content'].rstrip() + ' [/INST] '-}}
{%- else -%}
{{-'' + message['content'] + '</s> ' -}}
{{-'' + message['content'] + '</s>' -}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{-''-}}
{%- endif -%}
{%- endif -%}
56 changes: 55 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ document.querySelector(".header_bar").addEventListener("click", function(event)
//------------------------------------------------
// Keyboard shortcuts
//------------------------------------------------
let previousTabId = "chat-tab-button";
document.addEventListener("keydown", function(event) {

// Stop generation on Esc pressed
Expand Down Expand Up @@ -97,6 +98,19 @@ document.addEventListener("keydown", function(event) {
document.getElementById("Impersonate").click();
}

// Switch between tabs on Tab
else if (!event.ctrlKey && !event.shiftKey && event.key === "Tab") {
event.preventDefault();
var parametersButton = document.getElementById("parameters-button");
var parentContainer = parametersButton.parentNode;
var selectedChild = parentContainer.querySelector(".selected");
if (selectedChild.id == "parameters-button") {
document.getElementById(previousTabId).click();
} else {
previousTabId = selectedChild.id;
parametersButton.click();
}
}
});

//------------------------------------------------
Expand Down Expand Up @@ -248,7 +262,7 @@ button.addEventListener("click", function () {
hideMenu();
}
else {
showMenu();
showMenu();
}
});

Expand Down Expand Up @@ -371,3 +385,43 @@ new ResizeObserver(updateCssProperties)
.observe(document.querySelector("#chat-input textarea"));

window.addEventListener("resize", updateCssProperties);

//------------------------------------------------
// Keep track of the display width to position the past
// chats dropdown on desktop
//------------------------------------------------
function updateDocumentWidth() {
var updatedWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
document.documentElement.style.setProperty("--document-width", updatedWidth + "px");
}

updateDocumentWidth();
window.addEventListener("resize", updateDocumentWidth);

//------------------------------------------------
// Focus on the rename text area when it becomes visible
//------------------------------------------------
const renameTextArea = document.getElementById("rename-row").querySelector("textarea");

function respondToVisibility(element, callback) {
var options = {
root: document.documentElement,
};

var observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
callback(entry.intersectionRatio > 0);
});
}, options);

observer.observe(element);
}


function handleVisibilityChange(isVisible) {
if (isVisible) {
renameTextArea.focus();
}
}

respondToVisibility(renameTextArea, handleVisibilityChange);
4 changes: 2 additions & 2 deletions modules/RoPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def get_alpha_value(alpha, base):
Gets alpha_value from alpha_value and rope_freq_base
'''
if base > 0:
return (base/10000.) ** (63/64.)
return (base / 10000.) ** (63 / 64.)
else:
return alpha

Expand All @@ -15,4 +15,4 @@ def get_rope_freq_base(alpha, base):
if base > 0:
return base
else:
return 10000 * alpha ** (64/63.)
return 10000 * alpha ** (64 / 63.)
30 changes: 30 additions & 0 deletions modules/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from PIL import Image

import modules.shared as shared
from modules import utils
from modules.extensions import apply_extensions
from modules.html_generator import chat_html_wrapper, make_thumbnail
from modules.logging_colors import logger
Expand Down Expand Up @@ -517,6 +518,35 @@ def load_latest_history(state):
return history


def load_history_after_deletion(state, idx):
'''
Loads the latest history for the given character in chat or chat-instruct
mode, or the latest instruct history for instruct mode.
'''

if shared.args.multi_user:
return start_new_chat(state)

histories = find_all_histories(state)
idx = min(int(idx), len(histories) - 1)
idx = max(0, idx)

if len(histories) > 0:
history = load_history(histories[idx], state['character_menu'], state['mode'])
else:
history = start_new_chat(state)
histories = find_all_histories(state)

return history, gr.update(choices=histories, value=histories[idx])


def update_character_menu_after_deletion(idx):
characters = utils.get_available_characters()
idx = min(int(idx), len(characters) - 1)
idx = max(0, idx)
return gr.update(choices=characters, value=characters[idx])


def load_history(unique_id, character, mode):
p = get_history_file_path(unique_id, character, mode)

Expand Down
30 changes: 22 additions & 8 deletions modules/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def transformers_samplers():
'temperature',
'temperature_last',
'dynamic_temperature',
'dynamic_temperature_low',
'dynatemp_low',
'dynatemp_high',
'dynatemp_exponent',
'top_p',
'min_p',
'top_k',
Expand Down Expand Up @@ -223,7 +225,9 @@ def transformers_samplers():
'temperature',
'temperature_last',
'dynamic_temperature',
'dynamic_temperature_low',
'dynatemp_low',
'dynatemp_high',
'dynatemp_exponent',
'top_p',
'min_p',
'top_k',
Expand Down Expand Up @@ -277,7 +281,9 @@ def transformers_samplers():
'temperature',
'temperature_last',
'dynamic_temperature',
'dynamic_temperature_low',
'dynatemp_low',
'dynatemp_high',
'dynatemp_exponent',
'top_p',
'min_p',
'top_k',
Expand Down Expand Up @@ -350,12 +356,20 @@ def list_all_samplers():
return sorted(all_samplers)


def blacklist_samplers(loader):
def blacklist_samplers(loader, dynamic_temperature):
all_samplers = list_all_samplers()
if loader == 'All':
return [gr.update(visible=True) for sampler in all_samplers]
else:
return [gr.update(visible=True) if sampler in loaders_samplers[loader] else gr.update(visible=False) for sampler in all_samplers]
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


def get_model_types(loader):
Expand Down
16 changes: 8 additions & 8 deletions modules/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,14 @@ def AutoAWQ_loader(model_name):
model_dir = Path(f'{shared.args.model_dir}/{model_name}')

model = AutoAWQForCausalLM.from_quantized(
quant_path=model_dir,
max_new_tokens=shared.args.max_seq_len,
trust_remote_code=shared.args.trust_remote_code,
fuse_layers=not shared.args.no_inject_fused_attention,
max_memory=get_max_memory_dict(),
batch_size=1,
safetensors=any(model_dir.glob('*.safetensors')),
)
quant_path=model_dir,
max_new_tokens=shared.args.max_seq_len,
trust_remote_code=shared.args.trust_remote_code,
fuse_layers=not shared.args.no_inject_fused_attention,
max_memory=get_max_memory_dict(),
batch_size=1,
safetensors=any(model_dir.glob('*.safetensors')),
)

return model

Expand Down
19 changes: 13 additions & 6 deletions modules/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

from modules import shared
from modules.loaders import loaders_samplers
from modules.logging_colors import logger


def default_preset():
return {
'temperature': 1,
'temperature_last': False,
'dynamic_temperature': False,
'dynamic_temperature_low': 0.1,
'dynatemp_low': 1,
'dynatemp_high': 1,
'dynatemp_exponent': 1,
'top_p': 1,
'min_p': 0,
'top_k': 0,
Expand Down Expand Up @@ -48,11 +51,15 @@ def presets_params():
def load_preset(name):
generate_params = default_preset()
if name not in ['None', None, '']:
with open(Path(f'presets/{name}.yaml'), 'r') as infile:
preset = yaml.safe_load(infile)

for k in preset:
generate_params[k] = preset[k]
path = Path(f'presets/{name}.yaml')
if path.exists():
with open(path, 'r') as infile:
preset = yaml.safe_load(infile)

for k in preset:
generate_params[k] = preset[k]
else:
logger.error(f"The preset \"{name}\" does not exist under \"{path}\". Using the default parameters.")

return generate_params

Expand Down
Loading

0 comments on commit 2dc8db8

Please sign in to comment.