JacobLinCool / nycu-ivg-lab4

huggingface.co
Total runs: 0
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: November 15 2025

Introduction of nycu-ivg-lab4

Model Details of nycu-ivg-lab4

Flow Matching

NYCU: Image and Video Generation (2025 Fall)
Programming Assignment 4

Instructor: Yu-Lun Liu
TAs: Jie-Ying Lee , Ying-Huan Chen

Flow Matching Trajectory Visualization

๐Ÿ“‹ Overview

This assignment explores Flow Matching and its applications in generative modeling, consisting of 4 tasks (3 required + 1 bonus):

Grading Breakdown
Component Points Description
Task 1 20 pts 2D Flow Matching Implementation
Task 2 25 pts Image Flow Matching with Classifier-Free Guidance
Task 3 25 pts Rectified Flow for Faster Sampling
Task 4 +10 pts (Bonus) InstaFlow One-Step Generation
Report 30 pts Analysis, Visualizations, and Discussion
Total 100 pts + 10 pts Bonus

๐Ÿ“ Project Structure
.
โ”œโ”€โ”€ task1_2d_flow_matching/     # Task 1: 2D toy dataset visualization
โ”œโ”€โ”€ task2_image_flow_matching/  # Task 2: Image generation with FM
โ”œโ”€โ”€ task3_rectified_flow/       # Task 3: Rectified Flow implementation
โ”œโ”€โ”€ task4_instaflow/            # Task 4 (Bonus): One-step distillation
โ”œโ”€โ”€ image_common/               # Shared utilities for image tasks
โ”œโ”€โ”€ fid/                        # FID evaluation tools
โ””โ”€โ”€ requirements.txt            # Python dependencies

๐Ÿ”ง Setup
Prerequisites
  • Python 3.10 (required for compatibility)
  • CUDA-capable GPU (recommended)
Installation
pip install -r requirements.txt
Optional Dependencies

For Task 4 (InstaFlow):

pip install lpips  # For perceptual loss

๐Ÿ“š Recommended Reading

Understanding these papers will help you complete the assignment:

Core Papers
Background

๐ŸŽฏ Tasks
Task 1: 2D Flow Matching (20 points)

Objective : Implement and visualize Flow Matching on 2D toy datasets.

๐Ÿ“ Implementation Requirements

Complete the following in task1_2d_flow_matching/ :

fm.py :

  • โœ๏ธ FMScheduler.compute_psi_t() - Conditional flow ฯˆ_t(x|x_1)
  • โœ๏ธ FMScheduler.step() - Euler ODE solver
  • โœ๏ธ FlowMatching.get_loss() - CFM training objective
  • โœ๏ธ FlowMatching.sample() - Sampling with CFG support

network.py :

  • โœ๏ธ SimpleNet - MLP velocity network (reuse from Assignment 1)
๐Ÿš€ Execution
jupyter notebook task1_2d_flow_matching/fm_tutorial.ipynb

The notebook trains the model and visualizes flow trajectories on the Swiss-roll dataset.

๐Ÿ“Š Deliverables
  • Visualizations of learned trajectories
  • Chamfer Distance metrics
๐Ÿ’ฏ Grading Criteria
Chamfer Distance Points
< 40 20 pts
40 โ‰ค CD < 60 10 pts
โ‰ฅ 60 0 pts

Task 2: Image Flow Matching with CFG (25 points)

Objective : Implement Flow Matching for conditional image generation on AFHQ dataset.

๐Ÿ“ Implementation Requirements

Complete the following in image_common/fm.py (same TODOs as Task 1, adapted for images):

  • โœ๏ธ FMScheduler.compute_psi_t() - Conditional flow for images
  • โœ๏ธ FMScheduler.step() - Euler ODE solver
  • โœ๏ธ FlowMatching.get_loss() - CFM training loss
  • โœ๏ธ FlowMatching.sample() - Sampling with Classifier-Free Guidance
๐Ÿš€ Execution

Step 1: Download Dataset

python -m image_common.dataset

Step 2: Train Flow Matching Model

python -m task2_image_flow_matching.train --use_cfg

Training Configuration :

  • Batch size: 16
  • Training steps: 100,000
  • Learning rate: 2e-4 (with warmup: 200 steps)
  • CFG dropout: 0.1

Step 3: Generate Samples

python -m image_common.sampling \
  --use_cfg \
  --ckpt_path ${CKPT_PATH} \
  --save_dir ${SAVE_DIR} \
  --num_inference_steps 20

Step 4: Evaluate FID

python -m fid.measure_fid data/afhq/eval ${SAVE_DIR}
๐Ÿ“Š Deliverables
  • Training loss curves
  • FID scores with varying CFG scales (e.g., 1.0, 3.0, 7.5)
  • Comparison across inference steps (10, 20, 50)
  • Sample visualizations
๐Ÿ’ฏ Grading Criteria
FID Score (CFG=7.5) Points
< 30 25 pts
30 โ‰ค FID < 50 15 pts
โ‰ฅ 50 0 pts

Task 3: Rectified Flow (25 points)

Objective : Straighten generation trajectories through reflow procedure to enable faster sampling.

๐Ÿ“ Implementation Requirements

Complete the following in task3_rectified_flow/generate_reflow_data.py :

  • โœ๏ธ Generate synthetic (x_0, x_1) pairs by following the ODE trajectory of the Task 2 model
๐Ÿš€ Execution

Step 1: Generate Reflow Dataset

Create synthetic training pairs using your Task 2 model:

python -m task3_rectified_flow.generate_reflow_data \
  --ckpt_path ${TASK2_CKPT_PATH} \
  --num_samples 50000 \
  --save_dir data/afhq_reflow \
  --use_cfg \
  --num_inference_steps 20

Step 2: Train Rectified Flow Model

Train on synthetic pairs (same architecture/hyperparameters as Task 2):

python -m task3_rectified_flow.train_rectified \
  --reflow_data_path data/afhq_reflow \
  --use_cfg \
  --reflow_iteration 1

Training Configuration : Same as Task 2

Step 3: Generate with Fewer Steps

Test with reduced sampling steps:

# 5 steps
python -m image_common.sampling \
  --use_cfg \
  --ckpt_path ${RECTIFIED_CKPT_PATH} \
  --save_dir results/rectified_5steps \
  --num_inference_steps 5

# 10 steps
python -m image_common.sampling \
  --use_cfg \
  --ckpt_path ${RECTIFIED_CKPT_PATH} \
  --save_dir results/rectified_10steps \
  --num_inference_steps 10

Step 4: Evaluate FID

python -m fid.measure_fid data/afhq/eval results/rectified_5steps
python -m fid.measure_fid data/afhq/eval results/rectified_10steps
๐Ÿ“Š Deliverables
  • FID scores at different inference steps (5, 10, 20)
  • Comparison with Task 2 baseline (same step counts)
  • Speedup analysis (wall-clock time measurements)
  • Discussion : Why does rectified flow enable faster sampling?
๐Ÿ’ฏ Grading Criteria
Performance (CFG=7.5) Points
FID < 30 with 5 steps 25 pts
30 โ‰ค FID < 50 with 5 or 10 steps 15 pts
Otherwise 0 pts

Task 4 (Bonus): InstaFlow One-Step Generation (+10 points)

Objective : Distill a rectified flow model into a one-step generator.

โš ๏ธ Important Notice

This is a challenging bonus task requiring careful tuning. Attempt only after completing Tasks 1-3.

Key Challenges :

  • Mode collapse risk : One-step distillation is highly sensitive
  • Hyperparameter tuning : Extensive experimentation may be needed
  • Data quality : Requires large, diverse teacher-generated dataset
  • Training stability : May need multiple reflow iterations (2-3) before distillation

Recommendations :

  • Use high-quality 2-3x rectified flow teacher
  • Generate 10K-50K diverse training samples
  • Enable LPIPS loss for better perceptual quality
  • Monitor for collapse (blurry/similar outputs)
  • Budget sufficient time for iteration

This task tests your understanding of distillationโ€”don't be discouraged by initial failures!

๐Ÿ“ Implementation Requirements

Complete the following in image_common/instaflow.py :

InstaFlowModel.get_loss() - One-step distillation objective (Eq. 6):

  • โœ๏ธ Create t=0 tensor for batch
  • โœ๏ธ Predict velocity v(x_0, 0 | class_label)
  • โœ๏ธ Compute prediction: x1_pred = x_0 + v_pred
  • โœ๏ธ Calculate L2 loss: ||x1_pred - x1||ยฒ
  • โœ๏ธ Add optional LPIPS perceptual loss

InstaFlowModel.sample() - One-step inference:

  • โœ๏ธ Initialize x_0 with noise
  • โœ๏ธ Create t=0 tensor
  • โœ๏ธ Predict velocity (CFG is "baked in" during training)
  • โœ๏ธ Generate: x_1 = x_0 + v_pred
๐ŸŽ“ Conceptual Overview

Two-Phase Pipeline :

Flow Matching (CFG=7.5) โ†’ 1-Rectified Flow โ†’ InstaFlow (CFG=1.5) โ†’ ONE STEP
         Phase 1: Reflow          Phase 2: Distillation

Key Design Choices :

  • Different CFG scales: ฮฑโ‚=7.5 (quality) โ†’ ฮฑโ‚‚=1.5 (prevents over-saturation)
  • CFG effect embedded in model weights during training
  • Optional LPIPS improves perceptual quality
๐Ÿš€ Execution

Prerequisites :

pip install lpips  # Optional, for perceptual loss

Step 1: Generate Distillation Data

python -m task4_instaflow.generate_instaflow_data \
  --rf1_ckpt_path results/rectified_fm_XXX/last.ckpt \
  --num_samples 50000 \
  --save_dir data/afhq_instaflow \
  --use_cfg \
  --cfg_scale 1.5 \
  --save_images

Step 2: Train InstaFlow Student

python -m task4_instaflow.train_instaflow \
  --distill_data_path data/afhq_instaflow \
  --use_cfg \
  --use_lpips \
  --train_num_steps 100000

Training Configuration :

  • Batch size: 16
  • Steps: 100,000
  • Learning rate: 2e-4 (warmup: 200)
  • Optional: --use_lpips flag

Step 3: Evaluate

python -m task4_instaflow.evaluate_instaflow \
  --rf1_ckpt_path results/1rf_from_ddpm-XXX/last.ckpt \
  --instaflow_ckpt_path results/instaflow-XXX/last.ckpt \
  --save_dir results/instaflow_eval

Step 4: Sample (ONE STEP!)

python -m image_common.sampling \
  --use_cfg \
  --ckpt_path results/instaflow-XXX/last.ckpt \
  --save_dir results/instaflow_samples \
  --num_inference_steps 1

Step 5: Measure FID

python -m fid.measure_fid data/afhq/eval results/instaflow_samples
๐Ÿ“Š Deliverables

Quantitative Results :

  • FID scores for all pipeline stages
  • Generation speed (samples/second)
  • Speedup vs baselines (1-RF: 20 steps, base FM: 50 steps)

Qualitative Analysis :

  • Sample images from each stage
  • Visual quality comparison

Discussion Questions :

  1. Why is two-phase training necessary? (Why not distill FM directly?)
  2. Why not use LPIPS in Phase 1 (reflow)?
  3. Effect of LPIPS loss on visual quality in Phase 2
  4. Quality-speed tradeoff analysis
  5. Rationale for different CFG scales (ฮฑโ‚=7.5 vs ฮฑโ‚‚=1.5)
๐Ÿ’ฏ Grading Criteria
FID Score (1 step) Points
< 30 +10 pts
30 โ‰ค FID < 50 +5 pts
โ‰ฅ 50 0 pts

๐Ÿ“„ Report Requirements (30 points)

Your report should include:

Required Sections
  1. Introduction (2 pts)

    • Brief overview of Flow Matching
    • Assignment objectives
  2. Methodology (8 pts)

    • Implementation details for each task
    • Key equations and algorithms
    • Architecture choices
  3. Experiments & Results (12 pts)

    • Task 1 : Trajectory visualizations, Chamfer Distance
    • Task 2 : Loss curves, FID vs CFG scale, inference step analysis
    • Task 3 : FID comparison, speedup analysis, trajectory straightness
    • Task 4 (if attempted): Full pipeline results, ablation studies
  4. Discussion (6 pts)

    • Analysis of results
    • Challenges encountered and solutions
    • Comparison with related work
    • Answer discussion questions from each task
  5. Conclusion (2 pts)

    • Summary of findings
    • Future work suggestions
Formatting Guidelines
  • Format : PDF
  • Length : 6-10 pages (excluding code/appendices)
  • Figures : Clear, high-resolution images with captions
  • Tables : Organize quantitative results
  • References : Cite all papers and resources used

๐Ÿ“ฆ Submission
Submission Package

Create {STUDENT_ID}_lab4.zip with the following structure:

./submission/
โ”œโ”€โ”€ task1_2d_flow_matching/
โ”‚   โ”œโ”€โ”€ fm.py                              # TODO implementations
โ”‚   โ””โ”€โ”€ network.py                         # SimpleNet implementation
โ”œโ”€โ”€ task3_rectified_flow/
โ”‚   โ””โ”€โ”€ generate_reflow_data.py            # Data generation logic
โ”œโ”€โ”€ image_common/
โ”‚   โ”œโ”€โ”€ fm.py                              # Image FM implementation
โ”‚   โ””โ”€โ”€ instaflow.py                       # (Optional) InstaFlow model
โ””โ”€โ”€ report.pdf                             # Complete analysis report

Additional Files : If you modified any scripts beyond the required TODO files (e.g., training scripts, data loaders, network architectures), include them in your submission following the original directory structure. In your report, provide a section explaining:

  • Which additional files were modified
  • Rationale for each modification
  • How the changes improve performance or functionality
Submission Details
  • Deadline : 2025/11/20 (Thu.) 23:59
  • Platform : E3
  • Late Policy : No late submissions accepted
Academic Integrity

โš ๏ธ NO PLAGIARISM will be tolerated. All submissions will be checked for code similarity. Violations will result in:

  • Zero score for the assignment

Good luck! ๐Ÿš€

Runs of JacobLinCool nycu-ivg-lab4 on huggingface.co

0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About nycu-ivg-lab4 huggingface.co Model

nycu-ivg-lab4 huggingface.co

nycu-ivg-lab4 huggingface.co is an AI model on huggingface.co that provides nycu-ivg-lab4's model effect (), which can be used instantly with this JacobLinCool nycu-ivg-lab4 model. huggingface.co supports a free trial of the nycu-ivg-lab4 model, and also provides paid use of the nycu-ivg-lab4. Support call nycu-ivg-lab4 model through api, including Node.js, Python, http.

JacobLinCool nycu-ivg-lab4 online free

nycu-ivg-lab4 huggingface.co is an online trial and call api platform, which integrates nycu-ivg-lab4's modeling effects, including api services, and provides a free online trial of nycu-ivg-lab4, you can try nycu-ivg-lab4 online for free by clicking the link below.

JacobLinCool nycu-ivg-lab4 online free url in huggingface.co:

https://huggingface.co/JacobLinCool/nycu-ivg-lab4

nycu-ivg-lab4 install

nycu-ivg-lab4 is an open source model from GitHub that offers a free installation service, and any user can find nycu-ivg-lab4 on GitHub to install. At the same time, huggingface.co provides the effect of nycu-ivg-lab4 install, users can directly use nycu-ivg-lab4 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

nycu-ivg-lab4 install url in huggingface.co:

https://huggingface.co/JacobLinCool/nycu-ivg-lab4

Url of nycu-ivg-lab4

Provider of nycu-ivg-lab4 huggingface.co

JacobLinCool
ORGANIZATIONS

Other API from JacobLinCool

huggingface.co

Total runs: 4
Run Growth: 2
Growth Rate: 50.00%
Updated:December 16 2025