Meet YOLO26: next-gen vision AI.
Ultralytics
Back to Ultralytics Glossary

Generative Flow Networks (GFlowNets)

Discover how Generative Flow Networks (GFlowNets) use probabilistic modeling to sample diverse, high-reward discrete objects for drug discovery and causal learning.

Generative Flow Networks, or GFlowNets, are a powerful machine learning framework designed for probabilistic modeling and amortized sampling. They excel at generating discrete, compositional objects by treating the generation process as a sequential decision-making task. Instead of simply maximizing a reward, as is common in traditional reinforcement learning, GFlowNets learn to sample objects with a probability that is proportional to a predefined reward function. This allows them to discover diverse sets of high-reward candidates within exceptionally large sample spaces, effectively mitigating the model collapse that often plagues other generative architectures like Generative Adversarial Networks (GANs).

Link to this sectionCore Principles and Mechanisms#

GFlowNets operate by moving through a structured environment, adding building blocks step-by-step to construct a final object.

  • Forward and Backward Policies: A neural network predicts a forward policy, dictating the probability distribution over possible actions from a given state. By mapping trajectories through these states, the model learns the "flow" of probability.
  • Trajectory Balance Loss: Training often relies on optimization objectives like trajectory balance loss, which ensures that the probability of generating a specific object aligns closely with its observed reward. Proper hyperparameter tuning is essential to stabilize this loss function during training.
  • Proportional Sampling: By sampling proportionally to the reward rather than just seeking the absolute maximum, GFlowNets naturally enforce diversity, which is crucial when navigating complex combinatorial spaces.

Link to this sectionGFlowNets vs. Other Generative AI#

While Generative AI encompasses many techniques, GFlowNets occupy a unique niche. Standard Diffusion Models or techniques like Flow Matching typically transform continuous noise distributions into data. In contrast, GFlowNets are explicitly tailored for generating discrete structures, such as graphs or sequences. Furthermore, whereas standard reinforcement learning agents aim to find a single optimal path via the Markov Decision Process (MDP), GFlowNets map out multiple high-reward paths to ensure a broad variety of generated outputs.

Link to this sectionReal-World Applications#

The ability to generate diverse and highly optimized candidates makes GFlowNets particularly valuable in scientific and structural domains.

Link to this sectionImplementing the Forward Policy#

When building a GFlowNet, the forward policy must predict a probability distribution over the next possible steps. The following PyTorch snippet demonstrates how to define a simple policy layer and sample an action. While building vision models like Ultralytics YOLO26 requires predicting bounding box coordinates, a GFlowNet uses categorical distributions to select the next state in its generation path.

import torch
import torch.nn as nn
from torch.distributions import Categorical

# A simple linear policy mapping a 64-dim state to 4 possible actions
policy_network = nn.Sequential(nn.Linear(64, 4), nn.Softmax(dim=-1))

# Given a random state vector, compute action probabilities and sample
state = torch.randn(1, 64)
action_probs = policy_network(state)
sampled_action = Categorical(action_probs).sample()
print(f"Sampled Action: {sampled_action.item()}")

If you are developing complex AI solutions in Python, you can seamlessly annotate datasets, train, and deploy models using the Ultralytics Platform. Whether you are focusing on high-speed object detection tasks or exploring generative architectures, having a solid machine learning operations (MLOps) pipeline is essential for scaling your models effectively.

Explore solutions

Real-time AI that works with your team

AI in Robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Real-time AI that works with your team

AI in Logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Real-time AI that works with your team

AI in Retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Real-time AI that works with your team

AI in Healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Real-time AI that works with your team

AI in Manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Real-time AI that works with your operation

AI in Automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Real-time AI tailored to your operation

AI in Agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Real-time AI that works with your team

AI in Robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Real-time AI that works with your team

AI in Logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Real-time AI that works with your team

AI in Retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Real-time AI that works with your team

AI in Healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Real-time AI that works with your team

AI in Manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Real-time AI that works with your operation

AI in Automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Real-time AI tailored to your operation

AI in Agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Real-time AI that works with your team

AI in Robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Real-time AI that works with your team

AI in Logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Real-time AI that works with your team

AI in Retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Real-time AI that works with your team

AI in Healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Real-time AI that works with your team

AI in Manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Real-time AI that works with your operation

AI in Automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Real-time AI tailored to your operation

AI in Agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning