Download tests/test_sampling_scheduler.py from trixlyaisolutions/onnx: direct link, hf CLI and curl.
- Browser
- Download file 3.04 kB
-
https://huggingface.co/trixlyaisolutions/onnx/resolve/main/tests/test_sampling_scheduler.py
- Command line
-
hf download hf://trixlyaisolutions/onnx/tests/test_sampling_scheduler.py
-
curl -L -o test_sampling_scheduler.py https://huggingface.co/trixlyaisolutions/onnx/resolve/main/tests/test_sampling_scheduler.py
3.04 kB
| """``library.sampling.get_my_scheduler`` builds every ``--sample_sampler`` choice with the installed diffusers.""" | |
| import importlib.util | |
| import pytest | |
| from library import sampling | |
| from library.sampling import check_sampler_requirements, get_my_scheduler | |
| HAS_SCIPY = importlib.util.find_spec("scipy") is not None | |
| # every choice of --sample_sampler (library/args.py) except the scipy-dependent lms / k_lms | |
| SAMPLERS = [ | |
| "ddim", | |
| "pndm", | |
| "euler", | |
| "euler_a", | |
| "heun", | |
| "dpm_2", | |
| "dpm_2_a", | |
| "dpmsolver", | |
| "dpmsolver++", | |
| "dpmsingle", | |
| "k_euler", | |
| "k_euler_a", | |
| "k_dpm_2", | |
| "k_dpm_2_a", | |
| ] | |
| def test_every_sampler_builds_and_sets_timesteps(sampler, v_parameterization): | |
| scheduler = get_my_scheduler(sample_sampler=sampler, v_parameterization=v_parameterization) | |
| scheduler.set_timesteps(4) | |
| assert len(scheduler.timesteps) >= 4 | |
| if v_parameterization: | |
| assert scheduler.config.prediction_type == "v_prediction" | |
| def test_dpmsolver_uses_sigma_min_final_sigmas(): | |
| # diffusers rejects final_sigmas_type="zero" (its default) for the non-++ algorithm | |
| scheduler = get_my_scheduler(sample_sampler="dpmsolver", v_parameterization=False) | |
| assert scheduler.config.algorithm_type == "dpmsolver" | |
| assert scheduler.config.final_sigmas_type == "sigma_min" | |
| # dpmsolver++ keeps the diffusers default so its output is unchanged | |
| scheduler = get_my_scheduler(sample_sampler="dpmsolver++", v_parameterization=False) | |
| assert scheduler.config.final_sigmas_type == "zero" | |
| def test_dpmsingle_has_no_steps_offset(): | |
| scheduler = get_my_scheduler(sample_sampler="dpmsingle", v_parameterization=False) | |
| assert "steps_offset" not in scheduler.config | |
| def test_other_samplers_keep_steps_offset_one(sampler): | |
| scheduler = get_my_scheduler(sample_sampler=sampler, v_parameterization=False) | |
| assert scheduler.config.steps_offset == 1 | |
| def test_lms_builds_when_scipy_is_available(): | |
| scheduler = get_my_scheduler(sample_sampler="lms", v_parameterization=False) | |
| scheduler.set_timesteps(4) | |
| def test_lms_without_scipy_raises_a_clear_error(monkeypatch, sampler): | |
| monkeypatch.setattr(sampling.importlib.util, "find_spec", lambda name: None if name == "scipy" else object()) | |
| with pytest.raises(ImportError, match="pip install scipy"): | |
| check_sampler_requirements(sampler) | |
| with pytest.raises(ImportError, match="pip install scipy"): | |
| get_my_scheduler(sample_sampler=sampler, v_parameterization=False) | |
| def test_check_sampler_requirements_ignores_other_samplers(monkeypatch): | |
| monkeypatch.setattr(sampling.importlib.util, "find_spec", lambda name: None) | |
| for sampler in SAMPLERS: | |
| check_sampler_requirements(sampler) | |