round slider values to nice numbers

This commit is contained in:
Lincoln Stein 2023-08-09 16:08:36 -04:00 committed by Kent Keirsey
parent 1bfe9835cf
commit d0fee93aac

View File

@ -395,13 +395,23 @@ Use cursor arrows to make a checkbox selection, and space to toggle.
max_width=80, max_width=80,
scroll_exit=True, scroll_exit=True,
) )
self.max_cache_size = self.add_widget_intelligent( self.nextrely += 1
IntTitleSlider, self.add_widget_intelligent(
npyscreen.TitleFixedText,
name="RAM cache size (GB). Make this at least large enough to hold a single full model.", name="RAM cache size (GB). Make this at least large enough to hold a single full model.",
value=clip(old_opts.max_cache_size, range=(3.0, MAX_RAM)), begin_entry_at=0,
out_of=MAX_RAM, editable=False,
lowest=3, color="CONTROL",
begin_entry_at=6, scroll_exit=True,
)
self.nextrely -= 1
self.max_cache_size = self.add_widget_intelligent(
npyscreen.Slider,
value=clip(old_opts.max_cache_size, range=(3.0, MAX_RAM), step=0.5),
out_of=round(MAX_RAM),
lowest=0.0,
step=0.5,
relx=8,
scroll_exit=True, scroll_exit=True,
) )
if HAS_CUDA: if HAS_CUDA:
@ -417,7 +427,7 @@ Use cursor arrows to make a checkbox selection, and space to toggle.
self.nextrely -= 1 self.nextrely -= 1
self.max_vram_cache_size = self.add_widget_intelligent( self.max_vram_cache_size = self.add_widget_intelligent(
npyscreen.Slider, npyscreen.Slider,
value=clip(old_opts.max_vram_cache_size, range=(0, MAX_VRAM)), value=clip(old_opts.max_vram_cache_size, range=(0, MAX_VRAM), step=0.25),
out_of=round(MAX_VRAM * 2) / 2, out_of=round(MAX_VRAM * 2) / 2,
lowest=0.0, lowest=0.0,
relx=8, relx=8,
@ -596,13 +606,13 @@ def default_user_selections(program_opts: Namespace) -> InstallSelections:
# ------------------------------------- # -------------------------------------
def clip(value: float, range: tuple[float, float]) -> float: def clip(value: float, range: tuple[float, float], step: float) -> float:
minimum, maximum = range minimum, maximum = range
if value < minimum: if value < minimum:
value = minimum value = minimum
if value > maximum: if value > maximum:
value = maximum value = maximum
return value return round(value / step) * step
# ------------------------------------- # -------------------------------------