Skip to content

About

Second Order Rectified Flow. Developed by JamesSand

Resources

Stars

3 stars

Watchers

2 watching

Forks

Repository files navigation

Rectified Flow

By JamesSand

0 Releated Works

Here is the code for training the second order model.

Please cite our related papers which using second order method.

High-Order Matching for One-Step Shortcut Diffusion Models

@article{chen2025high,  
  title={High-Order Matching for One-Step Shortcut Diffusion Models},  
  author={Chen, Bo and Gong, Chengyue and Li, Xiaoyu and Liang, Yingyu and Sha, Zhizhou and Shi, Zhenmei and Song, Zhao and Wan, Mingda},  
  journal={arXiv preprint arXiv:2502.00688},  
  year={2025}  
}

Hofar: High-order augmentation of flow autoregressive transformers

@article{liang2025hofar,  
  title={Hofar: High-order augmentation of flow autoregressive transformers},  
  author={Liang, Yingyu and Sha, Zhizhou and Shi, Zhenmei and Song, Zhao and Wan, Mingda},  
  journal={arXiv preprint arXiv:2503.08032},  
  year={2025}  
}

Force Matching with Relativistic Constraints: A Physics-Inspired Approach to Stable and Efficient Generative Modeling

@article{cao2025force,  
  title={Force Matching with Relativistic Constraints: A Physics-Inspired Approach to Stable and Efficient Generative Modeling},  
  author={Cao, Yang and Chen, Bo and Li, Xiaoyu and Liang, Yingyu and Sha, Zhizhou and Shi, Zhenmei and Song, Zhao and Wan, Mingda},  
  journal={arXiv preprint arXiv:2502.08150},  
  year={2025}  
}
Model Architecture
Figure 1

The First Order model is defined at here

class MLP(nn.Module):
    def __init__(self, input_dim=2, hidden_num=100):
        super().__init__()
        self.fc1 = nn.Linear(input_dim+1, hidden_num, bias=True)
        self.fc2 = nn.Linear(hidden_num, hidden_num, bias=True)
        self.fc3 = nn.Linear(hidden_num, input_dim, bias=True)
        self.act = lambda x: torch.tanh(x)

    def forward(self, x_input, t):
        # We only input zero order here, so we have a dimension d input
        inputs = torch.cat([x_input, t], dim=1)
        x = self.fc1(inputs)
        x = self.act(x)
        x = self.fc2(x)
        x = self.act(x)
        x = self.fc3(x)

        return x

The Second Order model is defined at here

class MLP_2nd_order(nn.Module):
    def __init__(self, input_dim=2, hidden_num=100):
        super().__init__()
        self.fc1 = nn.Linear(input_dim + input_dim + 1, hidden_num, bias=True)
        self.fc2 = nn.Linear(hidden_num, hidden_num, bias=True)
        self.fc3 = nn.Linear(hidden_num, input_dim, bias=True)
        self.act = lambda x: torch.tanh(x)

    def forward(self, first_order_input, x_input, t):
        # We concate zero order and first order here, to get a dimension 2d input
        inputs = torch.cat([first_order_input, x_input, t], dim=1)
        x = self.fc1(inputs)
        x = self.act(x)
        x = self.fc2(x)
        x = self.act(x)
        x = self.fc3(x)

        return x
Visualization Result

first order weight: 1; second order weight: 1e-11

Figure 1 Figure 2

first order weight: 1; second order weight: 1e-8

Figure 1 Figure 2

first order weight: 1e6; second order weight: 1

Figure 1 Figure 2

1 Env setup

pip install -r requirements.txt

2 Run code

python second_order_code.py

3 Visualize results

Please refer to model_eval.ipynb

About

Second Order Rectified Flow. Developed by JamesSand

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages