Spaces:
Sleeping
Sleeping
add: orange theme and 32 lower lim
Browse files
app.py
CHANGED
|
@@ -24,12 +24,17 @@ def predict(label: int, steps: int):
|
|
| 24 |
yield image, f"trajectory checkpoint {idx}/{total} | integration step {step_idx}/{total_steps}"
|
| 25 |
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
gr.Markdown("# MNIST Flow")
|
| 29 |
gr.Markdown(
|
| 30 |
"Flow-matching DiT model for MNIST digits. "
|
| 31 |
"The demo streams one sample from noise to digit with fixed CFG=2.0. "
|
| 32 |
-
"Sampling caps ODE steps at 128 and shows
|
| 33 |
)
|
| 34 |
|
| 35 |
grid = gr.Image(label="Trajectory", show_label=True)
|
|
@@ -37,9 +42,9 @@ with gr.Blocks(title="MNIST Flow") as demo:
|
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
label = gr.Dropdown([str(i) for i in range(10)], value="1", label="Label")
|
| 40 |
-
steps = gr.Slider(
|
| 41 |
|
| 42 |
-
generate_btn = gr.Button("Generate")
|
| 43 |
|
| 44 |
generate_btn.click(
|
| 45 |
fn=predict,
|
|
|
|
| 24 |
yield image, f"trajectory checkpoint {idx}/{total} | integration step {step_idx}/{total_steps}"
|
| 25 |
|
| 26 |
|
| 27 |
+
theme = gr.themes.Default(
|
| 28 |
+
primary_hue="orange",
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
with gr.Blocks(title="MNIST Flow", theme=theme) as demo:
|
| 33 |
gr.Markdown("# MNIST Flow")
|
| 34 |
gr.Markdown(
|
| 35 |
"Flow-matching DiT model for MNIST digits. "
|
| 36 |
"The demo streams one sample from noise to digit with fixed CFG=2.0. "
|
| 37 |
+
"Sampling caps ODE steps at 128 and shows 32 trajectory checkpoints."
|
| 38 |
)
|
| 39 |
|
| 40 |
grid = gr.Image(label="Trajectory", show_label=True)
|
|
|
|
| 42 |
|
| 43 |
with gr.Row():
|
| 44 |
label = gr.Dropdown([str(i) for i in range(10)], value="1", label="Label")
|
| 45 |
+
steps = gr.Slider(32, 128, value=128, step=1, label="Steps")
|
| 46 |
|
| 47 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
| 48 |
|
| 49 |
generate_btn.click(
|
| 50 |
fn=predict,
|
model.py
CHANGED
|
@@ -39,7 +39,7 @@ MODEL_CONFIG = {
|
|
| 39 |
INFER_CONFIG = {
|
| 40 |
"steps": 128,
|
| 41 |
"cfg_scale": 2.0,
|
| 42 |
-
"trajectory_checkpoints":
|
| 43 |
}
|
| 44 |
|
| 45 |
DTYPES = {
|
|
@@ -543,7 +543,7 @@ def flow_image_generate(
|
|
| 543 |
uncond_context = uncond_context.to(device=context.device, dtype=context.dtype)
|
| 544 |
|
| 545 |
history: list[tuple[int, torch.Tensor]] = []
|
| 546 |
-
checkpoint_count = max(
|
| 547 |
checkpoint_indices = np.linspace(1, steps, num=checkpoint_count, dtype=int).tolist()
|
| 548 |
checkpoint_indices = sorted(set(max(1, min(steps, idx)) for idx in checkpoint_indices))
|
| 549 |
|
|
@@ -677,7 +677,7 @@ def generate_grid_image(label: int, steps: int, num_samples: int) -> Image.Image
|
|
| 677 |
@torch.inference_mode()
|
| 678 |
def iter_trajectory_frames(label: int, steps: int):
|
| 679 |
model, device, _ = load_model()
|
| 680 |
-
steps = max(
|
| 681 |
context = torch.full((1,), int(label), device=device, dtype=torch.long)
|
| 682 |
prompt = torch.empty((1, 0), device=device, dtype=torch.long)
|
| 683 |
null_label_id = int(MODEL_CONFIG["null_label_id"])
|
|
|
|
| 39 |
INFER_CONFIG = {
|
| 40 |
"steps": 128,
|
| 41 |
"cfg_scale": 2.0,
|
| 42 |
+
"trajectory_checkpoints": 32,
|
| 43 |
}
|
| 44 |
|
| 45 |
DTYPES = {
|
|
|
|
| 543 |
uncond_context = uncond_context.to(device=context.device, dtype=context.dtype)
|
| 544 |
|
| 545 |
history: list[tuple[int, torch.Tensor]] = []
|
| 546 |
+
checkpoint_count = max(32, int(INFER_CONFIG["trajectory_checkpoints"]))
|
| 547 |
checkpoint_indices = np.linspace(1, steps, num=checkpoint_count, dtype=int).tolist()
|
| 548 |
checkpoint_indices = sorted(set(max(1, min(steps, idx)) for idx in checkpoint_indices))
|
| 549 |
|
|
|
|
| 677 |
@torch.inference_mode()
|
| 678 |
def iter_trajectory_frames(label: int, steps: int):
|
| 679 |
model, device, _ = load_model()
|
| 680 |
+
steps = max(32, min(int(steps), 128))
|
| 681 |
context = torch.full((1,), int(label), device=device, dtype=torch.long)
|
| 682 |
prompt = torch.empty((1, 0), device=device, dtype=torch.long)
|
| 683 |
null_label_id = int(MODEL_CONFIG["null_label_id"])
|