MCPcopy
hub / github.com/Stability-AI/generative-models / init_sampling

Function init_sampling

scripts/demo/streamlit_helpers.py:326–377  ·  view source on GitHub ↗
(
    key=1,
    img2img_strength=1.0,
    specify_num_samples=True,
    stage2strength=None,
)

Source from the content-addressed store, hash-verified

324
325
326def init_sampling(
327 key=1,
328 img2img_strength=1.0,
329 specify_num_samples=True,
330 stage2strength=None,
331):
332 num_rows, num_cols = 1, 1
333 if specify_num_samples:
334 num_cols = st.number_input(
335 f"num cols #{key}", value=2, min_value=1, max_value=10
336 )
337
338 steps = st.sidebar.number_input(
339 f"steps #{key}", value=40, min_value=1, max_value=1000
340 )
341 sampler = st.sidebar.selectbox(
342 f"Sampler #{key}",
343 [
344 "EulerEDMSampler",
345 "HeunEDMSampler",
346 "EulerAncestralSampler",
347 "DPMPP2SAncestralSampler",
348 "DPMPP2MSampler",
349 "LinearMultistepSampler",
350 ],
351 0,
352 )
353 discretization = st.sidebar.selectbox(
354 f"Discretization #{key}",
355 [
356 "LegacyDDPMDiscretization",
357 "EDMDiscretization",
358 ],
359 )
360
361 discretization_config = get_discretization(discretization, key=key)
362
363 guider_config = get_guider(key=key)
364
365 sampler = get_sampler(sampler, steps, discretization_config, guider_config, key=key)
366 if img2img_strength < 1.0:
367 st.warning(
368 f"Wrapping {sampler.__class__.__name__} with Img2ImgDiscretizationWrapper"
369 )
370 sampler.discretization = Img2ImgDiscretizationWrapper(
371 sampler.discretization, strength=img2img_strength
372 )
373 if stage2strength is not None:
374 sampler.discretization = Txt2NoisyDiscretizationWrapper(
375 sampler.discretization, strength=stage2strength, original_steps=steps
376 )
377 return sampler, num_rows, num_cols
378
379
380def get_discretization(discretization, key=1):

Callers 3

run_txt2imgFunction · 0.85
run_img2imgFunction · 0.85
sampling.pyFile · 0.85

Calls 5

get_discretizationFunction · 0.85
get_guiderFunction · 0.85
get_samplerFunction · 0.85

Tested by

no test coverage detected