Files
hao-ai-lab-FastVideo/fastvideo/tests/api/test_request_resolution.py
T
Davids048andClaude Opus 5.5 38096b94a3 [refactor]: resolve request settings against the model's preset defaults
resolve_generation_request in fastvideo/api/resolution.py runs resolution
steps over the settings sections of a GenerationRequest (sampling, runtime,
output, stage_overrides) and freezes them as a ResolvedRequest. The explicit
paths are the ones the request tracked while it was parsed or built. Prompts,
inputs, state, plan, and extensions are request data and are left out, so
large tensors are not copied.

fastvideo/api/request_resolution.py adds resolve_request(request, model_path).
Its step, fill_sampling_defaults[preset <name>], sets each setting that the
request did not write to the model's preset default
(SamplingParam.from_pretrained). This is the same source that
request_to_sampling_param starts from, and a test checks that the two agree
field by field.

VideoGenerator attaches the ResolvedRequest to each GenerationResult as
resolved_request, so the source of every setting can be looked up. The golden
request snapshots record request_resolution_decisions; nothing else changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012M91wnVFmPEvJ9h39r5BH7
2026-10-02 20:23:05 +00:00

44 lines
2.1 KiB
Python

# SPDX-License-Identifier: Apache-2.0
"""Request resolution records the source of each setting and agrees with the SamplingParam built for the request."""
from dataclasses import fields
import pytest
from fastvideo.api.compat import normalize_generation_request, request_to_sampling_param
from fastvideo.api.request_resolution import resolve_request
from fastvideo.api.schema import OutputConfig, RequestRuntimeConfig, SamplingConfig
from fastvideo.tests.api.config_snapshot import isolated_environment
WAN_T2V = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
LTX2 = "FastVideo/LTX2-Distilled-Diffusers"
def test_request_values_and_preset_defaults_are_told_apart():
with isolated_environment():
request = normalize_generation_request({"prompt": "a cat", "sampling": {"seed": 7}})
resolved = resolve_request(request, model_path=WAN_T2V)
seed = resolved.provenance("sampling.seed")
assert (seed.value, seed.source, seed.explicit) == (7, "input", True)
frames = resolved.provenance("sampling.num_frames")
assert (frames.source, frames.explicit) == ("fill_sampling_defaults[preset wan_t2v_1_3b]", False)
@pytest.mark.parametrize(("model_path", "raw"), [
(WAN_T2V, {"prompt": "a cat"}),
(WAN_T2V, {"prompt": "a cat", "sampling": {"num_inference_steps": 12, "guidance_scale": 4.0, "height": 720}}),
(LTX2, {"prompt": "a cat", "output": {"save_video": False}}),
])
def test_resolved_settings_match_the_sampling_param(model_path, raw):
with isolated_environment():
request = normalize_generation_request(raw)
resolved = resolve_request(request, model_path=model_path)
sampling_param = request_to_sampling_param(request, model_path=model_path)
for section, config_type in (("sampling", SamplingConfig), ("runtime", RequestRuntimeConfig),
("output", OutputConfig)):
for config_field in fields(config_type):
if hasattr(sampling_param, config_field.name):
resolved_value = resolved.to_dict()[section][config_field.name]
assert resolved_value == getattr(sampling_param, config_field.name), f"{section}.{config_field.name}"