Skip to content

Commit

Permalink
Don't require do_sample, just listen to temp, top_p, top_k
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudotensor committed Mar 18, 2024
1 parent 6ac38aa commit af346e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,9 +1516,9 @@ def main(
max_total_input_tokens = max_total_input_tokens_public if max_total_input_tokens is None else max_total_input_tokens
allow_upload_to_user_data = False
input_lines = 1 # ensure set, for ease of use
temperature = 0.2 if temperature is None else temperature
temperature = 0.3 if temperature is None else temperature
top_p = 1.0 if top_p is None else top_p
top_k = 70 if top_k is None else top_k
top_k = 1 if top_k is None else top_k
penalty_alpha = 0.0 if penalty_alpha is None else penalty_alpha
if is_hf:
do_sample = True if do_sample is None else do_sample
Expand Down Expand Up @@ -3783,8 +3783,6 @@ def evaluate(
extract_frames = extract_frames0
if seed is None:
seed = 0
if seed == 0 and do_sample:
seed = randint(0, 32000)

if isinstance(langchain_agents, str):
if langchain_agents.strip().startswith('['):
Expand Down Expand Up @@ -3940,11 +3938,15 @@ def evaluate(
top_p = min(max(1e-3, top_p), 1.0)
top_k = min(max(1, int(top_k)), 100)
penalty_alpha = min(2.0, max(0.0, penalty_alpha))
if temperature > 0.0 or top_p < 1.0 or top_k > 1:
do_sample = True
if not do_sample:
temperature = 0
top_p = 1.0
top_k = 1
seed = 1
if seed == 0 and do_sample:
seed = randint(0, 32000)
# Note: Could do below, but for now gradio way can control do_sample directly
# elif temperature >= 0.01:
# do_sample = True
Expand Down Expand Up @@ -5244,19 +5246,19 @@ def get_generate_params(model_lower,
else:
prompt_type = prompt_type or ''
if use_defaults:
temperature = 1.0 if temperature is None else temperature
temperature = 0.0 if temperature is None else temperature
top_p = 1.0 if top_p is None else top_p
top_k = 40 if top_k is None else top_k
top_k = 1 if top_k is None else top_k
penalty_alpha = 0 if penalty_alpha is None else penalty_alpha
num_beams = num_beams or 1
max_new_tokens = max_new_tokens or 512
repetition_penalty = repetition_penalty or 1.07
num_return_sequences = min(num_beams, num_return_sequences or 1)
do_sample = False if do_sample is None else do_sample
else:
temperature = 0.1 if temperature is None else temperature
temperature = 0.0 if temperature is None else temperature
top_p = 1.0 if top_p is None else top_p
top_k = 40 if top_k is None else top_k
top_k = 1 if top_k is None else top_k
penalty_alpha = 0 if penalty_alpha is None else penalty_alpha
num_beams = num_beams or 1
max_new_tokens = max_new_tokens or 1024
Expand Down
9 changes: 5 additions & 4 deletions src/gradio_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,8 @@ def show_llava(x):
value=kwargs['stream_output'])
do_sample = gr.Checkbox(label="Sample",
info="Enable sampler (required for use of temperature, top_p, top_k). If temperature=0 is set, this is forced to False.",
value=kwargs['do_sample'])
value=kwargs['do_sample'],
visible=False)
seed = gr.Number(value=0,
minimum=0,
step=1,
Expand All @@ -1716,14 +1717,14 @@ def show_llava(x):
temperature = gr.Slider(minimum=0, maximum=2,
value=kwargs['temperature'],
label="Temperature",
info="Lower is deterministic, higher more creative")
info="Lower is deterministic, higher more creative (e.g. 0.3 to 0.75)")
top_p = gr.Slider(minimum=1e-3, maximum=1.0,
value=kwargs['top_p'], label="Top p",
info="Cumulative probability of tokens to sample from")
info="Cumulative probability of tokens to sample from (e.g. 0.7)")
top_k = gr.Slider(
minimum=1, maximum=100, step=1,
value=kwargs['top_k'], label="Top k",
info='Num. tokens to sample from'
info='Num. tokens to sample from (e.g. 5 to 70)'
)
penalty_alpha = gr.Slider(
minimum=0.0, maximum=2.0, step=0.01,
Expand Down

0 comments on commit af346e3

Please sign in to comment.