Dynamic Temperature HF loader support (#5174)
--------- Co-authored-by: oobabooga <112222186+oobabooga@users.noreply.github.com>
This commit is contained in:
parent
3eca20c015
commit
48327cc5c4
14 changed files with 184 additions and 8 deletions
17
extensions/dynatemp_with_range/README.md
Normal file
17
extensions/dynatemp_with_range/README.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# dynatemp_with_range
|
||||
|
||||
This extension makes it possible to set the minimum and maximum temperatures for dynamic temperature explicitly.
|
||||
|
||||
For instance, you can directly set
|
||||
|
||||
```
|
||||
min_T = 0.1
|
||||
max_T = 3
|
||||
```
|
||||
|
||||
instead of having to convert that to
|
||||
|
||||
```
|
||||
T = 1.55
|
||||
dynatemp = 1.45
|
||||
```
|
50
extensions/dynatemp_with_range/script.py
Normal file
50
extensions/dynatemp_with_range/script.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import gradio as gr
|
||||
|
||||
params = {
|
||||
"activate": True,
|
||||
"minimum_temperature": 0.1,
|
||||
"maximum_temperature": 2,
|
||||
}
|
||||
|
||||
def convert_to_dynatemp():
|
||||
temperature = 0.5 * (params["minimum_temperature"] + params["maximum_temperature"])
|
||||
dynatemp = params["maximum_temperature"] - temperature
|
||||
return temperature, dynatemp
|
||||
|
||||
|
||||
def state_modifier(state):
|
||||
"""
|
||||
Modifies the state variable, which is a dictionary containing the input
|
||||
values in the UI like sliders and checkboxes.
|
||||
"""
|
||||
|
||||
if params["activate"]:
|
||||
temperature, dynatemp = convert_to_dynatemp()
|
||||
|
||||
state["temperature"] = temperature
|
||||
state["dynatemp"] = dynatemp
|
||||
|
||||
return state
|
||||
|
||||
|
||||
def generate_info():
|
||||
temperature, dynatemp = convert_to_dynatemp()
|
||||
return f"The combination above is equivalent to: T={temperature:.2f}, dynatemp={dynatemp:.2f}"
|
||||
|
||||
|
||||
def ui():
|
||||
activate = gr.Checkbox(value=params['activate'], label='Activate Dynamic Temperature Range', info='When checked, the default temperature/dynatemp parameters are ignored and the parameters below are used instead.')
|
||||
with gr.Row():
|
||||
minimum_temperature = gr.Slider(0, 5, step=0.01, label="Minimum temperature", value=params["minimum_temperature"], interactive=True)
|
||||
maximum_temperature = gr.Slider(0, 5, step=0.01, label="Maximum temperature", value=params["maximum_temperature"], interactive=True)
|
||||
|
||||
info = gr.HTML(generate_info())
|
||||
|
||||
activate.change(lambda x: params.update({"activate": x}), activate, None)
|
||||
minimum_temperature.change(
|
||||
lambda x: params.update({"minimum_temperature": x}), minimum_temperature, None).then(
|
||||
generate_info, None, info, show_progress=False)
|
||||
|
||||
maximum_temperature.change(
|
||||
lambda x: params.update({"maximum_temperature": x}), maximum_temperature, None).then(
|
||||
generate_info, None, info, show_progress=False)
|
|
@ -8,6 +8,7 @@ from pydantic import BaseModel, Field
|
|||
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
|
||||
dynatemp: float = 0
|
||||
top_k: int = 0
|
||||
repetition_penalty: float = 1
|
||||
repetition_penalty_range: int = 1024
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue