AMD MIGraphX

repository·develop·Indexed 43 days ago

https://github.com/rocm/amdmigraphx

A graph inference engine designed to accelerate machine learning model inference on AMD hardware. It includes support for various Stable Diffusion versions (1.5, 2.1, 3, and XL) and ControlNet, providing tools for ONNX model conversion, FP16 quantization, and performance benchmarking on ROCm 6.0.

Tokens
81.2K
Snippets
214
Records
296
Agent score
56%

What's inside MIGraphX

  1. Overview of the MIGraphX driver CLI

    develop

    The migraphx-driver is a command-line tool used to interact with the MIGraphX execution engine without writing custom code. It allows you to load, compile, run, and profile deep learning models.

    Installation Locations:

    • Binary installation: /opt/rocm/bin/migraphx-driver
    • Source build: AMDMIGraphX/build/bin/migraphx-driver
  2. Explore AMD MIGraphX usage and utility examples

    develop

    The examples/migraphx directory contains practical implementations and guides for working with AMD MIGraphX. You can find examples for:

    • C++ Graph Operations: How to parse, load, and save graph programs using the C++ API.
    • TensorFlow 1.x Integration: How to export frozen graphs specifically for TF1.
    • TensorFlow 2.x Integration: How to export frozen graphs for TF2.
    • Containerization: Using the MIGraphX Docker container for isolated environments.
    • Driver Interaction: Working with the MIGraphX driver.
  3. Explore Vision Inference Examples

    develop

    MIGraphX provides several inference examples for vision tasks, implemented in both C++ and Python. These examples demonstrate how to run specific models using the MIGraphX runtime.

    C++ Examples

    • MNIST: Implementation of the MNIST digit recognition task in C++.

    Python Examples

    • Resnet50: Inference for the ResNet50 architecture.
    • Super Resolution: Implementation of super-resolution tasks.
    • NFNet: Inference for NFNet models.
    • U-Net: Implementation of the U-Net segmentation architecture.
    • 3D-UNet: Implementation of the 3D U-Net architecture.
    • YOLOv4: Implementation of the YOLOv4 object detection model.
    • YOLO26: Implementation of the YOLO26 object detection model.
  4. Explore AMD MIGraphX usage examples

    develop

    The examples/ directory provides practical implementations of common MIGraphX use cases across different domains. You can find specialized examples for the following categories:

    • MIGraphX usage and utilities: Core library usage patterns and helper utilities.
    • Vision inference examples: Implementations for computer vision tasks.
    • Natural language inference examples: Implementations for NLP tasks.
    • Diffusion inference examples: Implementations for generative diffusion models.
  5. What MIGraphX provides for deep learning compilation

    develop

    MIGraphX is a deep learning (DL) compiler designed to improve inference performance on AMD GPUs by analyzing a model's compute graph and applying program transformations.

    Key capabilities include:

    • End-to-end workflow: Handles both the compilation and execution of DL models on AMD hardware.
    • Multi-language support: Provides both C++ and Python APIs.
    • Model Input Formats: Supports ONNX, TensorFlow, and PyTorch (via the torch_migraphx integration). It also provides an ONNX Runtime execution provider.
    • Hardware Targets: Optimized for AMD Navi (consumer) and MI (server) GPUs.
    • Supported Data Types: Supports FP16, BF16, OCP FP8, INT8, and INT4.

    Optimization Mechanism

    The compiler improves latency and throughput primarily through kernel fusion. This process merges compatible operations into a single kernel launch, which reduces launch overhead and minimizes unnecessary host-to-device memory reads/writes.

  6. What are Op Builders and how do they work?

    develop

    Op Builders are abstractions used to simplify the creation of complex operations by composing multiple low-level MIGraphX primitive operators (e.g., dot, multibroadcast, slice, add) into a single high-level operation (e.g., GEMM, Convolution, MatMul).

    Key characteristics:

    • No new IR constructs: They do not introduce new types of constructs into the MIGraphX Intermediate Representation (IR); they merely insert a sequence of existing instructions into the module.
    • Code Reuse: They are designed to reduce duplication across different parsers (like TensorFlow or ONNX). A single builder acts as a superset of functionality that various parsers configure via attributes.
    • Composition: Builders can call other builders (e.g., an Einsum builder might internally call a MatMul builder).
  7. How MIGraphX matchers work

    develop

    Matchers are a way to compose multiple predicates to identify specific instructions within a program. They allow for complex pattern matching by combining simple matchers. For example, a composite matcher m(m1, m2) first checks for a match of m, followed by a match for m1 and then m2 in sequence.

    Commonly used matchers include:

    • name(string): Matches an instruction where the operator equals the specified name.
    • arg(index): Matches a specific argument of an instruction.
    • args(...): A convenience matcher that matches a sequence of arguments, removing the need to manually specify indices like arg(0), arg(1), etc.
    // Match a 'sum' operator
    auto match_sum = name("sum");
    
    // Match a 'sum' operator with a specific output shape
    auto match_sum = name("sum")(standard_shape());
    
    // Match a 'sum' operator with two arguments that are literals
    auto match_sum = name("sum")(args(name("@literal"), name("@literal")));
  8. Understand MIGraphX Program and Instruction abstractions

    develop
    In the MIGraphX internal API, a migraphx::internal::program represents the parsed model graph. The graph is composed of migraphx::internal::instruction objects, which represent individual operations. To reference specific operations within a program, use migraphx::internal::instruction_ref.
  9. Inspect operator output buffers using program::run_trace

    develop

    The program::run_trace API allows you to inspect operator output buffers during program evaluation. You provide a callback function that receives a trace_info object. This object exposes:

    • The operator name.
    • A host-side copy of each operator's result.

    This is useful for debugging or verifying the data flowing through specific parts of a compiled graph.

  10. Add new datasets to the Test Generator

    develop

    To add a new dataset (e.g., Video), create a new Python file within the sample_generator/dataset/ directory and implement a class that inherits from Base.

    Existing supported datasets include:

    • Image: imagenet
    • Text: squad
    • Audio: librispeech

    Note: After adding a dataset, you must update generate.py to include it in the generation logic.

  11. Quantize a MIGraphX program to FP16 or INT8

    develop

    You can improve performance and reduce memory usage by quantizing your graph program.

    FP16 Quantization

    Apply simple 16-bit floating point precision using migraphx::quantize_fp16(prog).

    INT8 Quantization

    INT8 requires a calibration step to map floating point ranges to integer values. You must provide calibration data for the input parameters using migraphx::quantize_int8_options and migraphx::program_parameters.

    // FP16
    migraphx::quantize_fp16(prog);
    
    // INT8
    std::vector<float> calib_dig; // ... load data
    
    migraphx::quantize_int8_options quant_opts;
    migraphx::program_parameters quant_params;
    auto param_shapes = prog.get_parameter_shapes();
    for(auto&& name : param_shapes.names())
    {
        quant_params.add(name, migraphx::argument(param_shapes[name], calib_dig.data()));
    }
    
    quant_opts.add_calibration_data(quant_params);
    migraphx::quantize_int8(prog, targ, quant_opts);