Ax Adaptive Experimentation Platform

repository·main·Indexed 23 days ago

https://github.com/facebook/ax

Ax is a general-purpose platform for managing, deploying, and automating adaptive experiments. It utilizes machine-learning guided processes, such as Bayesian optimization, to identify optimal configurations efficiently. The ax-platform package provides a Client API to configure experiments, manage trial execution, and analyze results using tools like Pareto frontier retrieval and surrogate model predictions.

Tokens
28.5K
Snippets
58
Records
141
Agent score
84%

What's inside Ax

  1. Explore the unique capabilities of Ax

    main

    Ax provides several advanced features for real-world optimization tasks:

    • Expressive API: Handles complex search spaces, multiple objectives, constraints on parameters and outcomes, and noisy observations. It supports parallel design suggestions (synchronous and asynchronous) and early-stopping of evaluations.
    • State-of-the-art Methods: Leverages Bayesian optimization algorithms implemented in BoTorch.
    • Flexibility: Highly configurable, allowing users to plug in novel optimization algorithms, models, and experimentation flows.
    • Production Readiness: Includes automation, orchestration features, and robust error handling for large-scale deployment.
  2. Understand Bayesian Optimization in Ax

    main

    Ax uses Bayesian Optimization (BO) as its core optimization engine. BO is an adaptive experimentation method that balances exploration (learning about unknown parameter regions) and exploitation (refining known good parameter regions).

    Ax implements BO by:

    1. Building a surrogate model (typically a Gaussian Process) to predict outcomes and uncertainty at unobserved points.
    2. Using an acquisition function to identify the next best candidate parameterization to evaluate.
    3. Iteratively updating the surrogate model with new observations.

    This approach is particularly effective for expensive-to-evaluate objective functions where minimizing the number of evaluations is critical.

  3. Understand Ax core concepts and terminology

    main

    To use Ax effectively, familiarize yourself with these core concepts:

    • Client: The top-level entrypoint for interacting with Ax. It manages the lifecycle of an experiment (creating trials, fetching data, and analyzing results).
    • Experiment: The base object for conducting an optimization. It contains the search space, optimization configuration, trials, and data.
    • Trial: A single execution or evaluation of one or more arms. Trials are stateful and have statuses like RUNNING, COMPLETED, or FAILED.
    • Arm: A specific parameterization within a search space.
    • Search space: The design space (continuous, discrete, or mixed) defining the parameters to be tuned, including optional Parameter Constraints (restrictions on parameter values relative to each other).
    • Parameter: A configurable quantity (continuous, ordinal, or categorical) assigned to an arm.
    • Objective: The outcome the optimization aims to minimize or maximize.
    • Outcome Constraint: A bound (absolute or relative) on an outcome that the optimization aims to satisfy.
    • Metric: A component responsible for fetching data from a deployed trial.
    • Runner: A component responsible for deploying a trial and optionally monitoring its execution.
    • Generation Strategy: A graph of components specifying how new candidate arms are generated, enabling the use of different models throughout the optimization.
    • Analysis: The tables, plots, and visualizations Ax produces to help understand optimization results.
    • Baseline: A specific parameterization chosen as the control when using relative outcome constraints or plotting relative effects.
    • Pareto Frontier: In multi-objective optimization, the set of non-dominated solutions representing the best trade-offs between all objectives.
    • SEM: Standard error of the metric's mean. If not provided, it defaults to np.nan, and Ax infers the value from measurements collected during experimentation.
  4. Use Ax Analyses to understand experiments

    main

    Ax's Analysis module provides a framework for producing plots, tables, and messages to help understand experiments. Analyses implement a compute method that consumes an Experiment, GenerationStrategy, and/or Adapter to output a collection of AnalysisCard objects.

    There are three base classes provided by Ax:

    1. Analysis: For creating tables.
    2. PlotlyAnalysis: For producing plots using the Plotly library.
    3. MarkdownAnalysis: For producing messages.

    Analysis cards can be saved to the database using save_analysis_cards, allowing for pre-computation and later display.

  5. Understand the Generation Strategy concept

    main

    A GenerationStrategy in Ax acts as a finite state machine that defines the optimization methodology for an experiment. It pre-specifies optimization algorithms and the dynamic conditions (transitions) for moving between them.

    A strategy consists of:

    • Generation Nodes: Represent a specific 'generation purpose' (e.g., Quasi-random initialization or Bayesian optimization) that produces new trials.
    • Node Transitions: Edges between nodes defined by TransitionCriterion. A transition occurs when all criteria on an edge are met.

    Note: Not all nodes in a strategy must be traversed during an experiment.

  6. Understand the use cases for Ax

    main

    Ax is a machine learning platform designed to automate and guide the experimentation process for tuning configurations. It is most effective for problems that are expensive to evaluate or where the number of evaluations must be limited.

    Key use cases include:

    • Machine Learning: Tuning hyperparameters like learning rates.
    • Infrastructure & Compilers: Optimizing 'magic numbers' or compiler flags.
    • Engineering: Tuning design parameters in physical engineering tasks.
    • A/B Testing: Optimizing discrete configurations (e.g., different variants of a test).
    • Simulations: Managing costly simulations using adaptive experimentation techniques.

    Ax supports continuous (integer or floating point), discrete, and mixed-valued search spaces using Bayesian optimization.

  7. Understand the Ax Data Model and Optimization Process

    main

    Ax uses an iterative 'ask-tell' process to find optimal points (called Arms) by balancing exploration and exploitation. The optimization process is managed through three high-order components:

    • Experiment: Tracks the entire optimization process, including state, Trials, SearchSpace, and OptimizationConfig.
    • GenerationStrategy: Defines the methodology used to produce the next Arms to try.
    • Orchestrator (optional): Automates the full experiment, including trial deployment and data fetching.

    Note: It is recommended to interact with the optimization process via the Client API (using methods like Client.get_next_trials and Client.complete_trial) rather than interacting with the Experiment object directly.

  8. Configure multi-objective optimization with Ax Client

    main

    To perform multi-objective optimization (MOO), use the configure_optimization method on an Ax Client instance. You specify multiple objectives by providing a comma-separated string of metric names.

    By default, objectives are assumed to be maximized. To minimize an objective, prepend the metric name with a minus sign (-).

    Example objective strings:

    • "-cost, utility": Minimizes cost and maximizes utility.
    • "metric_a, metric_b": Maximizes both metric_a and metric_b.
    client.configure_optimization(objectives="-cost, utility")
  9. Use the Ax Orchestrator for closed-loop experiments

    main

    The Orchestrator is a closed-loop manager class designed to automate the entire experiment lifecycle. It asynchronously deploys trial runs to external systems (like training job queues, simulators, or A/B test managers), polls for status, fetches results, and uses those results to generate new trials.

    Key capabilities include:

    • Closed-loop execution: Run an entire experiment with minimal code.
    • Concurrency management: Maintain user-defined limits for parallel trials.
    • Failure tolerance: Manage and track tolerated levels of failed trial runs.
    • Persistence: Supports SQL storage for easy resumption of experiments.
  10. Save an Ax experiment to a SQL database

    main

    To save experiment data to a SQL database, initialize a Client using a StorageConfig object. The StorageConfig requires a database URL (e.g., for SQLite, MySQL, or PostgreSQL). The Ax Client automatically persists experiment data, including configuration and metric setup, to the specified database at every stage.

    client = Client()
    
    url = "sqlite:///path/to/database.db"
    storage_config = StorageConfig(url = url)
    
    client.configure_experiment(...)
    client.configure_optimization(...)
  11. Configure node transition priority

    main
    A GenerationNode can have multiple outgoing transition edges to different nodes. If multiple edges are possible, the GenerationStrategy uses the order of the transition_criteria attribute on the source node to determine priority. The strategy will transition to the target node of the first edge where all transition criteria are met.
  12. Run the Ax website development server with Docusaurus

    main

    To run the Ax website locally, you need Node.js >= 18.x and Yarn.

    1. Navigate to the website directory.
    2. Install dependencies with yarn install.
    3. Start the server with yarn start.
    4. Access the site at http://localhost:3000.

    Note: You may need to switch to the "Next" version of the website documentation to see your latest changes.

    cd website
    yarn install
    yarn start