Ultralytics YOLO27:
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).

Core 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.

GFlowNets 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.

Real-World Applications#

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

Implementing 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

Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision 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
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision 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
Computer vision in agriculture

Computer vision 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
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision 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
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision 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
Computer vision in agriculture

Computer vision 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
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision 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
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision 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
Computer vision in agriculture

Computer vision 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