Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into baijumeswani/decoder-pipeline
  • Loading branch information
baijumeswani committed Dec 16, 2024
2 parents 11dbed2 + 7735e10 commit 0130a51
Show file tree
Hide file tree
Showing 63 changed files with 4,802 additions and 127 deletions.
22 changes: 22 additions & 0 deletions .pipelines/macos-ios-cocoapods-publishing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
parameters:
- name: ort_version
displayName: 'OnnxRuntime version'
type: string
default: '1.20.0'

- name: build_config
displayName: 'Build Configuration'
type: string
default: 'Release'
values:
- 'Debug'
- 'RelWithDebInfo'
- 'Release'
- 'MinSizeRel'

trigger: none
stages:
- template: stages/macos-ios-cocoapods-packaging-stage.yml
parameters:
ort_version: ${{ parameters.ort_version }}
build_config: ${{ parameters.build_config }}
1 change: 1 addition & 0 deletions .pipelines/stages/jobs/capi-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ jobs:
- template: steps/capi-appleframework-step.yml
parameters:
build_config: ${{ parameters.build_config }}
build_settings_file: "tools/ci_build/github/apple/default_full_ios_framework_build_settings.json"

- template: steps/compliant-and-cleanup-step.yml
68 changes: 68 additions & 0 deletions .pipelines/stages/jobs/macos-ios-cocoapods-packaging-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
parameters:
- name: build_config
type: string
- name: ort_version
type: string

jobs:
- job: macos_ios_cocoapods_packaging
pool:
vmImage: 'macOS-latest'
variables:
buildSettingsFile: "tools/ci_build/github/apple/default_full_apple_framework_build_settings.json"
cPodName: onnxruntime-genai-c
objcPodName: onnxruntime-genai-objc

workspace:
clean: all
steps:
- checkout: self
clean: true
submodules: none

- template: steps/utils/set-genai-version.yml
- template: steps/utils/set-cmake-build-type.yml
parameters:
build_config: ${{parameters.build_config}}


- task: CmdLine@2
displayName: Build MacOS & iOS CocoaPods Packages
inputs:
script: |
set -e -x
python3 -m pip install requests huggingface_hub
python3 tools/ci_build/github/apple/build_and_assemble_apple_pods.py \
--build-dir "$(Build.BinariesDirectory)/apple_framework" \
--staging-dir "$(Build.BinariesDirectory)/staging" \
--pod-version "$(genai_version)" \
--test \
--variant Full \
--build-settings-file "${{ variables.buildSettingsFile }}" \
--build-apple-framework-arg=--config=$(cmake_build_type) \
--ort-version ${{parameters.ort_version}}
- script: |
set -e -x
for POD_NAME in "${{ variables.cPodName}}" "${{ variables.objcPodName }}";
do
./tools/ci_build/github/apple/assemble_apple_packaging_artifacts.sh \
"$(Build.BinariesDirectory)/staging" \
"$(Build.ArtifactStagingDirectory)" \
"${POD_NAME}" \
"$(genai_version)"
done
# copy over helper script for use in release pipeline
# cp tools/ci_build/github/apple/package_release_tasks.py "$(Build.ArtifactStagingDirectory)"
displayName: "Assemble artifacts"
- script: |
set -e -x
ls -R "$(Build.ArtifactStagingDirectory)"
displayName: "List staged artifacts"
- publish: "$(Build.ArtifactStagingDirectory)"
artifact: "macos_ios_cocoapods_packaging_artifacts"
displayName: "Publish artifacts"
2 changes: 2 additions & 0 deletions .pipelines/stages/jobs/nuget-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ jobs:

- template: steps/utils/set-genai-version.yml

- task: NuGetAuthenticate@1

- powershell: |
dotnet --info
dotnet build Microsoft.ML.OnnxRuntimeGenAI.csproj -p:Configuration="$(buildConfig)" -p:IncludeMobileTargets=true --verbosity normal
Expand Down
9 changes: 7 additions & 2 deletions .pipelines/stages/jobs/steps/capi-appleframework-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ parameters:
- name: build_config
type: string
default: 'release'

- name: build_settings_file
type: string
steps:

- checkout: self
Expand All @@ -11,6 +12,9 @@ steps:
submodules: recursive

- template: utils/set-genai-version.yml
- template: utils/set-cmake-build-type.yml
parameters:
build_config: ${{parameters.build_config}}

- template: utils/set-nightly-build-option-variable.yml

Expand All @@ -19,7 +23,8 @@ steps:
python3 -m pip install requests
python3 tools/ci_build/github/apple/build_apple_framework.py \
--build_dir "$(Build.BinariesDirectory)/apple_framework" \
tools/ci_build/github/apple/default_full_ios_framework_build_settings.json
--config $(cmake_build_type) \
"${{ parameters.build_settings_file }}"
mkdir $(Build.BinariesDirectory)/artifacts
mkdir -p $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-genai.xcframework
Expand Down
15 changes: 15 additions & 0 deletions .pipelines/stages/macos-ios-cocoapods-packaging-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
- name: ort_version
type: string

- name: build_config
type: string
default: 'Release'

stages:
- stage: Build_MacOS_iOS_CocoaPods_Archive
jobs:
- template: jobs/macos-ios-cocoapods-packaging-job.yml
parameters:
ort_version: ${{ parameters.ort_version }}
build_config: ${{ parameters.build_config }}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ONNX Runtime generate() API

## *Main branch contains new API changes and examples in main branch reflect these changes. For example scripts compatible with current release (0.5.2), [see release branch](https://github.com/microsoft/onnxruntime-genai/tree/rel-0.5.2).*


[![Latest version](https://img.shields.io/nuget/vpre/Microsoft.ML.OnnxRuntimeGenAI.Managed?label=latest)](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntimeGenAI.Managed/absoluteLatest)

Run Llama, Phi, Gemma, Mistral with ONNX Runtime.
Expand Down Expand Up @@ -50,8 +53,6 @@ See https://onnxruntime.ai/docs/genai/howto/install

3. Run the model

*Main branch contains new API changes. For examples compatible with current release (0.5.2), [see release branch](https://github.com/microsoft/onnxruntime-genai/tree/rel-0.5.2).*

### Build from source / Next release (0.6.0)

```python
Expand Down
9 changes: 4 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,11 @@ def _validate_build_dir(args: argparse.Namespace):
# also tweak build directory name for mac builds
target_sys = "macOS"

# set to a config specific build dir if no build_dir specified from command arguments
args.build_dir = Path("build") / target_sys / args.config
args.build_dir = Path("build") / target_sys

# set to a config specific build dir. it should exist unless we're creating the cmake setup
is_strict = not args.update
# Use user-specified build_dir and ignore args.config
# This is to better accommodate the existing cmake presets which can uses arbitrary paths.
args.build_dir = args.build_dir.resolve(strict=is_strict)
args.build_dir = args.build_dir.resolve(strict=is_strict) / args.config


def _validate_cuda_args(args: argparse.Namespace):
Expand Down Expand Up @@ -505,6 +503,7 @@ def update(args: argparse.Namespace, env: dict[str, str]):
"-DENABLE_PYTHON=OFF",
"-DENABLE_TESTS=OFF",
"-DENABLE_MODEL_BENCHMARK=OFF",
"-DCMAKE_OSX_DEPLOYMENT_TARGET=" + args.apple_deploy_target,
f"-DBUILD_APPLE_FRAMEWORK={'ON' if args.build_apple_framework else 'OFF'}",
"-DPLATFORM_NAME=" + platform_name,
]
Expand Down
13 changes: 0 additions & 13 deletions examples/c/src/phi3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,6 @@ void CXX_API(const char* model_path) {
is_first_token = false;
}

// Show usage of GetOutput
std::unique_ptr<OgaTensor> output_logits = generator->GetOutput("logits");

// Assuming output_logits.Type() is float as it's logits
// Assuming shape is 1 dimensional with shape[0] being the size
auto logits = reinterpret_cast<float*>(output_logits->Data());

// Print out the logits using the following snippet, if needed
//auto shape = output_logits->Shape();
//for (size_t i=0; i < shape[0]; i++)
// std::cout << logits[i] << " ";
//std::cout << std::endl;

const auto num_tokens = generator->GetSequenceCount(0);
const auto new_token = generator->GetSequenceData(0)[num_tokens - 1];
std::cout << tokenizer_stream->Decode(new_token) << std::flush;
Expand Down
2 changes: 1 addition & 1 deletion src/models/decoder_only.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct DecoderOnly_State : State {
void RewindTo(size_t index) override;

private:
void UpdateInputsOutputs(DeviceSpan<int32_t>& next_tokens, DeviceSpan<int32_t> next_indices, int total_length);
void UpdateInputsOutputs(DeviceSpan<int32_t>& next_tokens, DeviceSpan<int32_t> beam_indices, int total_length);

const DecoderOnly_Model& model_;
CapturedGraphInfoPtr captured_graph_info_;
Expand Down
17 changes: 17 additions & 0 deletions src/objectivec/cxx_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// wrapper for ORT GenAI C/C++ API headers

#if defined(__clang__)
#pragma clang diagnostic push
// ignore clang documentation-related warnings
// instead, we will rely on Doxygen warnings for the C/C++ API headers
#pragma clang diagnostic ignored "-Wdocumentation"
#endif // defined(__clang__)

#include "ort_genai.h"

#if defined(__clang__)
#pragma clang diagnostic pop
#endif // defined(__clang__)
29 changes: 29 additions & 0 deletions src/objectivec/error_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#import <Foundation/Foundation.h>

#include <exception>

#import "cxx_api.h"

NS_ASSUME_NONNULL_BEGIN

extern NSString* const kOgaErrorDomain;

void OGASaveCodeAndDescriptionToError(int code, const char* description, NSError** error);
void OGASaveCodeAndDescriptionToError(int code, NSString* description, NSError** error);
void OGASaveExceptionToError(const std::exception& e, NSError** error);

// helper macros to catch and handle C++ exceptions
#define OGA_OBJC_API_IMPL_CATCH(error, failure_return_value) \
catch (const std::exception& e) { \
OGASaveExceptionToError(e, (error)); \
return (failure_return_value); \
}

#define OGA_OBJC_API_IMPL_CATCH_RETURNING_BOOL(error) OGA_OBJC_API_IMPL_CATCH(error, NO)

#define OGA_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error) OGA_OBJC_API_IMPL_CATCH(error, nil)

NS_ASSUME_NONNULL_END
34 changes: 34 additions & 0 deletions src/objectivec/error_utils.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#import "error_utils.h"

NS_ASSUME_NONNULL_BEGIN

NSString* const kOgaErrorDomain = @"onnxruntime-genai";
const int kOgaErrorCode = 0x0A;

void OGASaveCodeAndDescriptionToError(int code, const char* descriptionCstr, NSError** error) {
if (!error) return;

NSString* description = [NSString stringWithCString:descriptionCstr
encoding:NSUTF8StringEncoding];

*error = [NSError errorWithDomain:kOgaErrorDomain
code:code
userInfo:@{NSLocalizedDescriptionKey : description}];
}

void OGASaveCodeAndDescriptionToError(int code, NSString* description, NSError** error) {
if (!error) return;

*error = [NSError errorWithDomain:kOgaErrorDomain
code:code
userInfo:@{NSLocalizedDescriptionKey : description}];
}

void OGASaveExceptionToError(const std::exception& e, NSError** error) {
OGASaveCodeAndDescriptionToError(kOgaErrorCode, e.what(), error);
}

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 0130a51

Please sign in to comment.