-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration of CoreML Backend into Leela Chess Zero #1950
base: master
Are you sure you want to change the base?
Conversation
- Create coreml_backend namespace. - Create CoreML header file. - Create CoreML Objective-C++ source file. - Create CoreML constructor. - Compile and initialize MLModel in the CoreML constructor.
Introduce CoreMLModel class to encapsulate MLModel storage and retrieval.
Let CoreMLModel to accommodate multiple outputs for model predictions.
Improve CoreML model initialization and inference by setting MLComputeUnits to MLComputeUnitsCPUAndGPU for enhanced accuracy during forward evaluation. Update the forwardEval method to properly handle input data and log CoreML output.
Consolidated input array setup, added error checking and post-prediction calculations for output values, and output moves left in CoreML forward evaluation.
Added CoreML backend support with necessary frameworks check and file inclusion for the macOS build. This enhancement enables using CoreML for neural network computations, expanding functionality.
Extracts input setup and prediction functions to enhance modularity and readability.
Add Objective-C style configuration to .clang-format for consistent code formatting across different languages. This update ensures proper styling for Objective-C code, maintaining uniformity in the codebase.
Modified CoreML constructor to accept boolean parameters for WDL and moves_left settings, enhancing configurability and flexibility in model instantiation. This change improves the compatibility of the CoreML component.
Refactored the CoreML code to use exception throwing for error handling instead of returning null, in order to improve error reporting and handling. This change also includes signaling the semaphore after the model initialization task is complete. This commit addresses the need for more robust error handling and better signaling of task completion in the CoreML module.
Absolute error histogram
|
Backendbench
|
During the compilation process documented in Mac (5438) - LeelaChessZero/lc0, an error was encountered due to the |
To resolve a compilation error in LeelaChessZero/lc0 due to the unavailability of a Core ML framework method in macOS 12.3.1, the Xcode version in config.yml is updated to 14.3.1. This ensures compatibility with macOS 13.0 or later, potentially resolving the error.
Overview
This pull request introduces a CoreML backend for Leela Chess Zero (lc0), capitalizing on Apple's CoreML framework to significantly enhance neural network computations on macOS devices. By integrating this backend, lc0 gains considerable performance optimizations and expanded computational capabilities tailored for Apple hardware.
Implementation Highlights
coreml_backend
namespace, this phase includes the setup of essential CoreML header and source files, alongside the initialization of MLModel within this namespace..clang-format
has been updated to ensure uniform coding styles across C++ and Objective-C++ languages, maintaining code clarity and consistency.Prerequisites and Setup
Prior to the integration, it is imperative to build coremltools from a specific pull request (apple/coremltools#2087) pending the release of coremltools 7.2. The conversion of networks into CoreML models necessitates the use of
net_to_coreml.py
from the lczero-training repository, following the instructions delineated in LeelaChessZero/lczero-training#222.Converting Networks to CoreML Models:
lczero-training
repository and prepare the environment:Benchmarking lc0 with CoreML Backend:
Navigate to lc0's release directory and execute the benchmark command to evaluate performance:
Contribution and Review Request
This pull request seeks a comprehensive review of the CoreML backend's integration, focusing on its compatibility, performance enhancements, and alignment with lc0's architectural standards. Feedback, suggestions, and further optimizations are highly encouraged to ensure this significant feature's robust integration into lc0, fostering a seamless user experience on macOS platforms.