View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Videos

Abrir menú Cerrar menú
  • Colecciones
  • Todos los videos
  • Información

Más videos

  • Información
  • Código
  • Accelerate machine learning with Metal Performance Shaders Graph

    Metal Performance Shaders Graph is a compute engine that helps you build, compile, and execute customized multidimensional graphs for linear algebra, machine learning, computer vision, and image processing. Discover how MPSGraph can accelerate the popular TensorFlow platform through a Metal backend for Apple products. Learn how to add control flow to your graphs, manage the graph compilation for optimal performance, and use the MPSGraph operations to accelerate the hardest compute applications with only a few lines of code.

    Recursos

    • Training a Neural Network with Metal Performance Shaders
    • Metal Performance Shaders
    • Metal
    • Metal Shading Language Specification
      • Video HD
      • Video SD

    Videos relacionados

    WWDC22

    • Accelerate machine learning with Metal

    WWDC20

    • Build customized ML models with the Metal Performance Shaders Graph
  • Buscar este video…
    • 8:35 - Control dependencies 1

      // Execute the graph
      let results = graph.run(feeds: [inputTensor: inputs],
                              targetTensors: [exp],
                              targetOperations: [assign])
    • 9:01 - Control dependencies 2

      // Create control dependency
      
      let exp = graph.controlDependency(with: [assign],
                                        dependentBlock: { 
                                            return [graph.exponent(with: input, 
                                                                   name: nil)]
                                        },
                                        name: nil)
      
      // Execute the graph
      
      let results = graph.run(feeds: [inputTensor: inputs],
                              targetTensors: [exp],
                              targetOperations: nil)
    • 14:42 - Evaluation method

      // Create the graph
      
      let placeholder0 = graph.placeholder(shape: [1, 3], 
                                           dataType: .float32, 
                                           name: nil)
      
      let placeholder1 = graph.placeholder(shape: [2, 1], 
                                           dataType: .float32, 
                                           name: nil)
      
      let addTensor = graph.addition(placeholder0, 
                                     placeholder1, 
                                     name: nil)
      
      // Compile the graph into an executable
      
      let executable = graph.compile(with: nil,
                                     feeds: [placeholder0: MPSGraphShapedType(shape: [1, 3], 
                                                                              dataType: .float32),
                                             placeholder1: MPSGraphShapedType(shape: [2, 1], 
                                                                              dataType: .float32)],
                                     targetTensors: [addTensor],
                                     targetOperations: nil,
                                     compilationDescriptor: nil)
      
      // Execute the graph into an executable
      
      let fetch = executable.run(with: commandQueue,
                                 inputs: [MPSGraphTensorData(input0),        
                                          MPSGraphTensorData(input1)],
                                 results: nil,
                                 executionDescriptor: nil)
    • 16:38 - Disabling the type inference pass

      // Create the graph compilation descriptor
      
      let descriptor = MPSGraphCompilationDescriptor()
      
      // Disable type inference
      
      descriptor.disableTypeInference()
      
      // Compile the graph into an executable
      
      let executable = graph.compile(with: nil,
                                     feeds: /* feeds */,
                                     targetTensors: /* target tensors */,
                                     targetOperations: nil,
                                     compilationDescriptor: descriptor)
      
      // execute the graph
    • 19:22 - If/else in batch normalization

      // Different behavior during inference and training
      
      let results = graph.if(isTraining,
                             then: { ... },    // compute mean and variance
                             else: { ... },    // use running_mean and running_variance
                             name: nil)
    • 19:46 - If/else

      let predicate = graph.lessThan(a, 
                                     b, 
                                     name: nil)
      
      let results = graph.if(predicate,
          then: {[
              graph.addition(a, 
                             b, 
                             name: nil)
          ]},
          else: {[
              graph.subtraction(a, 
                                b, 
                                name: nil)
          ]},
          name: nil)
    • 20:58 - For loop 1

      var result = input0
      
      for i in 0..<4 {
          result *= input1
      }
    • 21:12 - For Loop 2

      // Initialize inputs
      
      let input0 = graph.placeholder(shape: [], 
                                     dataType: .int32, 
                                     name: nil)
      
      let input1 = graph.placeholder(shape: [], 
                                     dataType: .int32, 
                                     name: nil)
              
      let numberOfIterations = graph.constant(4, 
                                              shape: [], 
                                              dataType: .int32)
    • 21:33 - For Loop 3

      // Define Body
      
      let body = {
          (index: MPSGraphTensor, iterationArguments: [MPSGraphTensor]) -> [MPSGraphTensor] in
              let iterationResult = graph.multiplication(iterationArguments[0], input1, name: nil)
              return [iterationResult]
      }
    • 21:52 - For Loop 4

      // Create for loop operation
      
      let result = graph.for(numberOfIterations: numberOfIterations,
                             initialIterationArguments: [input0],
                             body: body)
    • 22:51 - While loop 1

      var result = initialValue
      
      while result < threshold {
          result *= multiplier
      }
    • 23:01 - While loop 2

      // Evaluate condition
      
      let condition = {
          (inputs: [MPSGraphTensor], returnTensors: NSMutableArray) -> MPSGraphTensor in
              let predicate = graph.lessThan(inputs[0], threshold, name: nil)
              returnTensors.add(inputs[0])
              return predicate
      }
    • 23:22 - While loop 3

      // Define body
      
      let body = {
          (inputs: [MPSGraphTensor]) -> [MPSGraphTensor] in
              let iterationResult = graph.multiplication(inputs[0], multiplier, name: nil)
              return [iterationResult]
      }
    • 23:33 - While loop 4

      // Create while loop operation
      
      let results = graph.while(initialInputs: [initialValue],
                                before: condition,
                                after: body,
                                name: nil)
    • 25:00 - Edge filter

      // Apply the laplacian edge filter on the source image
      
      let edges = graph.stencil(with: source, 
                                weights: laplacianWeights, 
                                descriptor: desc, 
                                name: nil)

Developer Footer

  • Videos
  • WWDC21
  • Accelerate machine learning with Metal Performance Shaders Graph
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines