Compute the conditional flow matching loss of a small linear velocity model on straight paths between data and noise.
xt=(1−t)xdata+txnoise,u=xnoise−xdata,v=xtW+twtime+b,ℓ=D1d=1∑D(vd−ud)2Here x_data holds the data samples xdata with shape (B, D), x_noise holds the paired Gaussian noise samples xnoise with the same shape, and t holds one time t in [0, 1] per sample with shape (B,). Time 0 is the data end of the path and time 1 is the noise end. The target velocity u is the constant speed of the straight path from data to noise. The toy velocity model multiplies xt by weight W (shape (D, D)), adds the per-sample time times time_weight wtime (shape (D,)) and adds bias b (shape (D,)). The per-sample loss ℓ is the mean squared error over the D features, and the batch loss is the mean of ℓ over the B samples.
Return a dict with the keys "x_t" and "target" holding PyTorch tensors of shape (B, D), "per_sample_loss" holding a tensor of shape (B,), all with the dtype and device of x_data, and "loss" holding the batch loss as a Python float.
Input: x_data = [[1.0,2.0],[-1.0,0.5]], x_noise = [[0.2,-0.4],[0.6,1.0]], t = [0.25,0.75], weight = [[0.5,-0.1],[0.2,0.3]], time_weight = [1.0,-0.5], bias = [0.0,0.1]
Output: {"x_t":[[0.8,1.4],[0.2,0.875]],"target":[[-0.8,-2.4],[1.6,0.5]],"loss":2.744577,"per_sample_loss":[5.182063,0.307091]}
Explanation: The first sample sits at t = 0.25, so x_t = 0.75 * (1, 2) + 0.25 * (0.2, -0.4) = (0.8, 1.4) and its target velocity is (0.2, -0.4) - (1, 2) = (-0.8, -2.4). The model predicts (0.93, 0.315), which gives a per-sample loss of 5.1821.
Input: x_data = [[0.5,-0.5,1.0],[2.0,0.0,-1.0]], x_noise = [[1.0,1.0,-1.0],[-0.3,0.8,0.4]], t = [0.0,1.0], weight = [[0.1,0.0,0.2],[0.0,-0.3,0.1],[0.4,0.2,0.0]], time_weight = [0.5,0.5,0.5], bias = [0.0,0.0,0.0]
Output: {"x_t":[[0.5,-0.5,1.0],[-0.3,0.8,0.4]],"target":[[0.5,1.5,-2.0],[-2.3,0.8,1.4]],"loss":2.5164,"per_sample_loss":[1.8425,3.1903]}
Input: x_data = [[1.0],[0.0],[-2.0]], x_noise = [[0.0],[1.0],[0.5]], t = [0.1,0.5,0.9], weight = [[0.0]], time_weight = [2.0], bias = [-1.0]
Output: {"x_t":[[0.9],[0.5],[0.25]],"target":[[-1.0],[1.0],[2.5]],"loss":1.31,"per_sample_loss":[0.04,1.0,2.89]}
t[:, None] turns the (B,) times into a (B, 1) column.
((a - b) ** 2).mean(dim=1) averages a squared error over the features of each row.
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Compute the conditional flow matching loss of a small linear velocity model on straight paths between data and noise.
xt=(1−t)xdata+txnoise,u=xnoise−xdata,v=xtW+twtime+b,ℓ=D1d=1∑D(vd−ud)2Here x_data holds the data samples xdata with shape (B, D), x_noise holds the paired Gaussian noise samples xnoise with the same shape, and t holds one time t in [0, 1] per sample with shape (B,). Time 0 is the data end of the path and time 1 is the noise end. The target velocity u is the constant speed of the straight path from data to noise. The toy velocity model multiplies xt by weight W (shape (D, D)), adds the per-sample time times time_weight wtime (shape (D,)) and adds bias b (shape (D,)). The per-sample loss ℓ is the mean squared error over the D features, and the batch loss is the mean of ℓ over the B samples.
Return a dict with the keys "x_t" and "target" holding PyTorch tensors of shape (B, D), "per_sample_loss" holding a tensor of shape (B,), all with the dtype and device of x_data, and "loss" holding the batch loss as a Python float.
Input: x_data = [[1.0,2.0],[-1.0,0.5]], x_noise = [[0.2,-0.4],[0.6,1.0]], t = [0.25,0.75], weight = [[0.5,-0.1],[0.2,0.3]], time_weight = [1.0,-0.5], bias = [0.0,0.1]
Output: {"x_t":[[0.8,1.4],[0.2,0.875]],"target":[[-0.8,-2.4],[1.6,0.5]],"loss":2.744577,"per_sample_loss":[5.182063,0.307091]}
Explanation: The first sample sits at t = 0.25, so x_t = 0.75 * (1, 2) + 0.25 * (0.2, -0.4) = (0.8, 1.4) and its target velocity is (0.2, -0.4) - (1, 2) = (-0.8, -2.4). The model predicts (0.93, 0.315), which gives a per-sample loss of 5.1821.
Input: x_data = [[0.5,-0.5,1.0],[2.0,0.0,-1.0]], x_noise = [[1.0,1.0,-1.0],[-0.3,0.8,0.4]], t = [0.0,1.0], weight = [[0.1,0.0,0.2],[0.0,-0.3,0.1],[0.4,0.2,0.0]], time_weight = [0.5,0.5,0.5], bias = [0.0,0.0,0.0]
Output: {"x_t":[[0.5,-0.5,1.0],[-0.3,0.8,0.4]],"target":[[0.5,1.5,-2.0],[-2.3,0.8,1.4]],"loss":2.5164,"per_sample_loss":[1.8425,3.1903]}
Input: x_data = [[1.0],[0.0],[-2.0]], x_noise = [[0.0],[1.0],[0.5]], t = [0.1,0.5,0.9], weight = [[0.0]], time_weight = [2.0], bias = [-1.0]
Output: {"x_t":[[0.9],[0.5],[0.25]],"target":[[-1.0],[1.0],[2.5]],"loss":1.31,"per_sample_loss":[0.04,1.0,2.89]}
t[:, None] turns the (B,) times into a (B, 1) column.
((a - b) ** 2).mean(dim=1) averages a squared error over the features of each row.
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array