Skip to content

Commit

Permalink
Merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanUnderhill committed Apr 17, 2024
2 parents aca309d + 92a5573 commit 2f5be41
Show file tree
Hide file tree
Showing 102 changed files with 3,608 additions and 568 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-linux-aarch64-1.17.1"
ort_zip: "onnxruntime-linux-aarch64-1.17.1.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-linux-aarch64-1.17.1.tgz"
ort_dir: "onnxruntime-linux-aarch64-1.17.3"
ort_zip: "onnxruntime-linux-aarch64-1.17.3.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-linux-aarch64-1.17.3.tgz"
jobs:
linux-cpu-arm64-build:
runs-on: [ "self-hosted", "1ES.Pool=onnxruntime-genai-Ubuntu2004-ARM-CPU" ]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linux-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-linux-x64-1.17.1"
ort_zip: "onnxruntime-linux-x64-1.17.1.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-linux-x64-1.17.1.tgz"
ort_dir: "onnxruntime-linux-x64-1.17.3"
ort_zip: "onnxruntime-linux-x64-1.17.3.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-linux-x64-1.17.3.tgz"

jobs:
linux_cpu_x64:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linux-cpu-x64-nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-linux-x64-1.17.1"
ort_zip: "onnxruntime-linux-x64-1.17.1.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-linux-x64-1.17.1.tgz"
ort_dir: "onnxruntime-linux-x64-1.17.3"
ort_zip: "onnxruntime-linux-x64-1.17.3.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-linux-x64-1.17.3.tgz"
jobs:
job:
runs-on: [ "self-hosted", "1ES.Pool=onnxruntime-genai-Ubuntu2204-AMD-CPU" ]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linux-gpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ concurrency:
cancel-in-progress: true

env:
ort_dir: "onnxruntime-linux-x64-gpu-1.17.1"
ort_zip: "onnxruntime-linux-x64-gpu-1.17.1.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-linux-x64-gpu-1.17.1.tgz"
ort_dir: "onnxruntime-linux-x64-gpu-1.17.3"
ort_zip: "onnxruntime-linux-x64-gpu-1.17.3.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-linux-x64-gpu-1.17.3.tgz"

jobs:
linux-gpu-x64-build:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/mac-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-osx-arm64-1.17.1"
ort_zip: "onnxruntime-osx-arm64-1.17.1.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-osx-arm64-1.17.1.tgz"
ort_dir: "onnxruntime-osx-arm64-1.17.3"
ort_zip: "onnxruntime-osx-arm64-1.17.3.tgz"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-osx-arm64-1.17.3.tgz"
jobs:
mac-cpu-arm64-build:
runs-on: macos-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/win-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-win-arm64-1.17.1"
ort_dir: "onnxruntime-win-arm64-1.17.3"
ort_zip: "$(ort_dir).zip"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/$(ort_zip)"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/$(ort_zip)"
binaryDir: 'build/cpu'

jobs:
Expand All @@ -33,7 +33,7 @@ jobs:

- name: Download OnnxRuntime
run: |
$env:ort_url = "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-win-arm64-1.17.1.zip"
$env:ort_url = "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-win-arm64-1.17.3.zip"
Invoke-WebRequest -Uri $env:ort_url -OutFile $env:ort_zip
- name: Unzip OnnxRuntime
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/win-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
ort_dir: "onnxruntime-win-x64-1.17.1"
ort_dir: "onnxruntime-win-x64-1.17.3"
ort_zip: "$(ort_dir).zip"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/$(ort_zip)"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/$(ort_zip)"
binaryDir: 'build/cpu'

jobs:
Expand All @@ -35,7 +35,7 @@ jobs:

- name: Download OnnxRuntime
run: |
$env:ort_url = "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-win-x64-1.17.1.zip"
$env:ort_url = "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-win-x64-1.17.3.zip"
Invoke-WebRequest -Uri $env:ort_url -OutFile $env:ort_zip
- name: Unzip OnnxRuntime
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/win-gpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ concurrency:
env:
AZCOPY_AUTO_LOGIN_TYPE: MSI
AZCOPY_MSI_CLIENT_ID: 63b63039-6328-442f-954b-5a64d124e5b4
ort_dir: "onnxruntime-win-x64-gpu-1.17.1"
ort_zip: "onnxruntime-win-x64-gpu-1.17.1.zip"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.1/onnxruntime-win-x64-gpu-1.17.1.zip"
ort_dir: "onnxruntime-win-x64-gpu-1.17.3"
ort_zip: "onnxruntime-win-x64-gpu-1.17.3.zip"
ort_url: "https://github.com/microsoft/onnxruntime/releases/download/v1.17.3/onnxruntime-win-x64-gpu-1.17.3.zip"
cuda_dir: "${{ github.workspace }}\\cuda_sdk"
cuda_version: "11.8"
CUDA_PATH: ${{ github.workspace }}\\cuda_sdk\\v11.8
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/test/test_models/*
/cache_models
/onnxruntime-linux-x64-*
/*.csv
*.csv
.idea
cache_dir
example-models
Expand All @@ -22,4 +22,6 @@ examples/python/genai_models
examples/python/hf_cache

!test/test_models/hf-internal-testing/
!test/test_models/hf-internal-testing/tiny-random-gpt2*/*.onnx
!test/test_models/hf-internal-testing/tiny-random-gpt2*/*.onnx

.ipynb_checkpoints/
2 changes: 1 addition & 1 deletion .pipelines/nuget-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parameters:
- name: ort_version
displayName: 'OnnxRuntime version'
type: string
default: '1.17.1'
default: '1.17.3'

- name: cuda_version
displayName: 'CUDA version'
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/pypl-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ parameters:
- name: ort_version
displayName: 'OnnxRuntime version'
type: string
default: '1.17.1'
default: '1.17.3'

- name: cuda_version
displayName: 'CUDA version'
Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ if(USE_CUDA AND CMAKE_CUDA_COMPILER AND CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(_DEBUG=1)
endif()

if(MSVC)
# set updated value for __cplusplus macro instead of 199711L
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
endif()

message(STATUS "Adding source files")

file(GLOB generator_srcs CONFIGURE_DEPENDS
Expand Down Expand Up @@ -127,6 +132,11 @@ else()
set(ONNXRUNTIME_EXTENSIONS_LIB "tfmtok_c.so")
endif()

file(GLOB onnxruntime_libs "${ORT_LIB_DIR}/${ONNXRUNTIME_FILES}")
if(USE_DML)
list(APPEND onnxruntime_libs "${ORT_LIB_DIR}/DirectML.dll")
endif()

if(NO_TOKENIZEROOT)
add_compile_definitions(NO_TOKENIZER=1)
message("----------------Tokenizer Disabled------------------")
Expand All @@ -148,6 +158,11 @@ if(ENABLE_PYTHON)
message("------------------Enabling Python Wheel------------------")
endif()

if(ENABLE_MODEL_BENCHMARK)
add_subdirectory("${CMAKE_SOURCE_DIR}/benchmark/c")
message("------------------Enabling model benchmark------------------")
endif()

if(NOT EXISTS "${ORT_LIB_DIR}/${ONNXRUNTIME_LIB}")
message(FATAL_ERROR "Expected the ONNX Runtime library to be found at ${ORT_LIB_DIR}/${ONNXRUNTIME_LIB}. Actual: Not found.")
endif()
Expand All @@ -158,7 +173,6 @@ if(USE_CUDA AND NOT EXISTS "${ORT_LIB_DIR}/${ONNXRUNTIME_PROVIDERS_CUDA_LIB}")
message(FATAL_ERROR "Expected the ONNX Runtime providers cuda library to be found at ${ORT_LIB_DIR}/${ONNXRUNTIME_PROVIDERS_CUDA_LIB}. Actual: Not found.")
endif()

file(GLOB onnxruntime_libs "${ORT_LIB_DIR}/${ONNXRUNTIME_FILES}")
target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR})
target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB})

Expand All @@ -182,7 +196,6 @@ if(MSVC)
endif()

# Copy the onnxruntime binaries into the build folder so it's found on launch
file(GLOB onnxruntime_libs "${ORT_LIB_DIR}/${ONNXRUNTIME_FILES}")
foreach(DLL_FILE ${onnxruntime_libs})
add_custom_command(
TARGET onnxruntime-genai POST_BUILD
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ See full documentation at [https://onnxruntime.ai/docs/genai].

[Install](https://onnxruntime.ai/docs/genai/howto/install) the onnxruntime-genai Python package.

1. Build the model
```shell
python -m onnxruntime_genai.models.builder -m microsoft/phi-2 -e cpu -p int4 -o ./models/phi2
```

2. Run inference
```python
import os
import onnxruntime_genai as og

model = og.Model(f'models/microsoft/phi-2')
model_path = os.path.abspath("./models/phi2")

model = og.Model(model_path)

tokenizer = og.Tokenizer(model)

Expand All @@ -64,7 +73,7 @@ prompt = '''def print_prime(n):

tokens = tokenizer.encode(prompt)

params = og.SearchParams(model)
params = og.GeneratorParams(model)
params.set_search_options({"max_length":200})
params.input_ids = tokens

Expand Down
2 changes: 1 addition & 1 deletion VERSION_INFO
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0rc4
0.2.0-dev
25 changes: 25 additions & 0 deletions benchmark/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set(model_benchmark_srcs
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/options.h
${CMAKE_CURRENT_SOURCE_DIR}/options.cpp
)

add_executable(model_benchmark ${model_benchmark_srcs})

target_include_directories(model_benchmark PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src # directory containing the ort_genai headers
)

target_link_libraries(model_benchmark PRIVATE onnxruntime-genai-static ${ONNXRUNTIME_LIB})

target_link_directories(model_benchmark PRIVATE ${ORT_LIB_DIR})

add_custom_command(TARGET model_benchmark POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${onnxruntime_libs} $<TARGET_FILE_DIR:model_benchmark>
)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${model_benchmark_srcs})
Loading

0 comments on commit 2f5be41

Please sign in to comment.