View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 代码
  • 深入探索 Core AI 模型编写与优化

    深入探索适用于 Apple 芯片的自定模型部署流程,同时充分发挥全新 Core AI 框架的优势。了解使用自定 Metal 内核编写模型的超实用技巧,以及平台感知压缩策略。全新的 Core AI 调试器可提供深度内在分析;还有 AI 辅助的工作流程引导你逐步完善,从最初的概念构思到优化后的设备端执行,全称助你一臂之力。

    章节

    • 0:00 - Introduction
    • 1:49 - Models and skills
    • 3:27 - Python workflow
    • 5:54 - Model optimization
    • 10:40 - Core AI Debugger
    • 19:27 - Advanced authoring
    • 20:43 - Custom Metal kernels
    • 23:01 - Model re-authoring
    • 28:46 - Next steps

    资源

    • Core AI PyTorch Extensions
    • Core AI Python
    • Core AI Optimization
    • Inspecting, debugging, and profiling Core AI models
    • Inspecting Core AI models with Core AI Debugger
    • Core AI
      • 高清视频
      • 标清视频

    相关视频

    WWDC26

    • 使用 MLX 在 Mac 上本地运行 AI 智能体
    • 使用 MLX 探索 Swift 中的数值计算
    • 使用 MLX 探索分布式推理和训练
  • 搜索此视频…
    • 3:27 - Define and export a PyTorch model

      import torch
      import torch.nn as nn
      
      # Define a simple model
      class MLP(nn.Module):
          def __init__(self):
              super().__init__()
              self.fc1 = nn.Linear(256, 512)
              self.fc2 = nn.Linear(512, 10)
      
          def forward(self, x):
              return self.fc2(torch.relu(self.fc1(x)))
      
      # Export with torch.export
      model = MLP().eval()
      example_input = (torch.randn(1, 256),)
      exported_program = torch.export.export(model, example_input)
    • 4:02 - Convert, optimize and run inference with Core AI

      import coreai
      import coreai_torch
      from coreai.runtime import NDArray
      
      # Convert to Core AI
      converter = coreai_torch.TorchConverter()
      converter.add_exported_program(
          exported_program,
          input_names=["features"], output_names=["logits"])
      core_ai_program = converter.to_coreai()
      
      # Optimize and save to .aimodel
      core_ai_program.optimize()
      asset = core_ai_program.save_asset("mlp.aimodel")
      
      # Run inference
      specialized_model = await AIModel.load("mlp.aimodel")
      specialized_function = specialized_model.load_function("main")
      result = await specialized_function({"features": NDArray(example[0].numpy())})
    • 21:12 - Define a SiLU Metal kernel with PyTorch reference

      import torch
      from coreai_torch.dsl import TorchMetalKernel, MetalParameter
      
      def silu_torch(x):
          return x * torch.sigmoid(x)
      
      SILU_MSL = """
      float val = float(x[gid]);
      float sig = 1.0f / (1.0f + exp(-val));
      y[gid] = TYPE(val * sig);
      """
      
      silu_kernel = TorchMetalKernel(
          name="fused_silu",
          input_names=["x"],
          result_names=["y"],
          src=SILU_MSL,
          torch_defn=silu_torch,
          metal_params=[MetalParameter("gid", "uint", "thread_position_in_grid")],
          template_dtypes={"x": "TYPE"},
      )
    • 22:09 - Use a custom Metal kernel and convert with TorchConverter

      class MyModel(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.linear = torch.nn.Linear(256, 256)
      
          def forward(self, x):
              h = self.linear(x)
              n = h.numel()
              return silu_kernel(
                  h,
                  threads_per_grid_size=(n, 1, 1),
                  threads_per_thread_group=(min(n, 256), 1, 1),
                  result_shapes=[h.shape],
              )
      
      exported_program = torch.export.export(MyModel(), (torch.randn(1, 256),))
      
      converter = coreai_torch.TorchConverter()
      converter.register_custom_kernels([silu_kernel])
      converter.add_exported_program(exported_program,
                                     input_names=["x"], output_names=["y"])
      deployable = converter.to_coreai()  # MSL integrated into asset
    • 0:00 - Introduction
    • Overview of Core AI's complete Python ecosystem for model deployment on Apple Silicon — covering the model lifecycle from optimization and conversion through debugging and app integration.

    • 1:49 - Models and skills
    • Introduction to the coreai-models open-source repository — ready-to-go model architectures, reusable components, and agent skills you can install into your coding assistant to leverage Core AI best practices from day one.

    • 3:27 - Python workflow
    • How to convert a PyTorch model to Core AI using coreai-torch — exporting a program with torch.export, running TorchConverter with input/output names, saving as an .aimodel asset, and performing inference from Python with numpy inputs.

    • 5:54 - Model optimization
    • How to compress models using coreai-opt's config-driven optimization library — demonstrated on SAM3 (850M parameters) using int4 per-channel symmetric quantization presets, reducing the model from 3GB to 430MB, and understanding the trade-offs of aggressive uniform compression.

    • 10:40 - Core AI Debugger
    • Introduction to Core AI Debugger — a standalone app for inspecting models on Apple platforms. Covers the navigator (PyTorch module hierarchy), structure viewer (operation graph), source viewer (original Python code), inspector (tensor details), and how to run a model on-device to inspect intermediate tensor outputs.

    • 19:27 - Advanced authoring
    • How advanced model authoring goes beyond end-to-end conversion — fusing multiple operations into a single kernel dispatch, and leveraging Core AI's pre-packaged fast kernels for heavy operations like Scaled Dot Product Attention.

    • 20:43 - Custom Metal kernels
    • How to embed custom Metal Shading Language kernels directly into a Core AI model asset — writing a PyTorch reference function alongside an MSL kernel, registering a TorchMetalKernel with TorchConverter, and shipping the kernel bundled inside the .aimodel file.

    • 23:01 - Model re-authoring
    • How to re-author a PyTorch model from scratch for power-efficient execution on iOS — demonstrated on SAM3 by splitting into three independent functions (image_encode, text_encode, detect), using convolutional projections and channels-first layouts, applying 4-bit palettization to the encoders, and achieving faster second inference by reusing cached image embeddings.

    • 28:46 - Next steps
    • Summary of the Core AI Python toolchain: convert with coreai-torch, optimize with coreai-opt, debug with Core AI Debugger, build on coreai-models examples, and use Core AI Skills in your coding agent.

Developer Footer

  • 视频
  • WWDC26
  • 深入探索 Core AI 模型编写与优化
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • 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 Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则