Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ WinML integration downloads `Microsoft.WindowsAppSDK.ML` via NuGet and copies he

```bash
# Python tests with test models
python -m pytest -sv test_onnxruntime_genai_api.py -k "test_name" --test_models ..\test_models
python -m pytest -sv test_onnxruntime_genai_api.py -k "test_name" --test_models ..\models

# C++ unit tests via CMake/CTest
ctest --build-config Release --output-on-failure
Expand Down Expand Up @@ -160,4 +160,4 @@ Tests are organized by language binding:
- **Python tests**: `test/python/`, includes end-to-end model testing
- **Platform tests**: Android/iOS tests run via emulator/simulator

Always test with actual model files from `test/test_models/` directory rather than mock data.
Always test with actual model files from `test/models/` directory rather than mock data.
7 changes: 6 additions & 1 deletion .github/instructions/python-model-builder.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ When generating or reviewing code in the Python Model Builder (`src/python/py/mo

Read both documents to understand the intended usage, supported models, design principles, and architectural constraints before suggesting or reviewing any code changes in this area.

When a node is inserted into the model, prefer using `self.make_op_name` as the wrapper method for `self.make_node` + `self.make_value` calls.
## Code Style Guidelines

1. When a node is inserted into the model, prefer using `self.make_op_name` as the wrapper method for `self.make_node` + `self.make_value` calls.
2. Ignore any CodeQL warnings about how an __init__ method calls an overridden method. These warnings are false positives and can be safely ignored. The warning message is: "this call to ABC in an initialization method is overwritten by XYZ".
3. Find ways to reduce code duplication by reusing existing functionality and implementing common patterns.
4. Discover ways to leverage the use of shared code in the base classes to avoid code duplication and improve maintainability.
8 changes: 4 additions & 4 deletions .github/workflows/linux-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ jobs:
set -e -x
ctest --test-dir build/cpu/src/java --build-config Release --verbose --timeout 10800

# This will also download all the test models to the test/test_models directory
# This will also download all the test models to the test/models directory
# These models are used by the python tests as well as C#, C++ and others.
- name: Run the Python tests
run: |
export ORTGENAI_LOG_ORT_LIB=1
python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models
python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/models

- name: Build the C# API and Run the C# Tests
run: |
Expand All @@ -155,8 +155,8 @@ jobs:
- name: Test the C# LLM Example with Tool Calling
run: |
export ORTGENAI_LOG_ORT_LIB=1
python3 test/python/special_tokens.py -p test/test_models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>"
./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/test_models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/test_models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
python3 test/python/special_tokens.py -p test/models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>"
./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose

- name: Run tests
run: |
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 @@ -136,7 +136,7 @@ jobs:
- name: Run the Python tests
run: |
export ORTGENAI_LOG_ORT_LIB=1
python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models --e2e
python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/models --e2e

- name: Build the C# API and Run the C# Tests
run: |
Expand All @@ -155,8 +155,8 @@ jobs:
- name: Test the C# LLM Example with Tool Calling
run: |
export ORTGENAI_LOG_ORT_LIB=1
python3 test/python/special_tokens.py -p test/test_models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>"
./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/test_models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/test_models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
python3 test/python/special_tokens.py -p test/models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>"
./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose

- name: Run Q&A Example
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-gpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ jobs:
${{ env.PYTHON_EXECUTABLE }} -m pip install -r test/python/cuda/torch/requirements.txt --user && \
${{ env.PYTHON_EXECUTABLE }} -m pip install -r test/python/cuda/ort/requirements.txt --user && \
${{ env.PYTHON_EXECUTABLE }} -m pip install /ort_genai_src/build/cuda/wheel/onnxruntime_genai*manylinux*.whl --no-deps --user && \
${{ env.PYTHON_EXECUTABLE }} test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models --e2e"
${{ env.PYTHON_EXECUTABLE }} test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/models --e2e"

# TODO: Enable this by adding dotnet to the docker image
# - name: Build the C# API and Run the C# Tests
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 @@ -114,7 +114,7 @@ jobs:

- name: Run the Python Tests
run: |
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\test_models"
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\models"

- name: Build the C# API and Run the C# Tests
run: |
Expand All @@ -130,8 +130,8 @@ jobs:

- name: Test the C# LLM Example with Tool Calling
run: |
python3 test\python\special_tokens.py -p test\test_models\qwen-2.5-0.5b\int4\cpu\tokenizer.json -s "<tool_call>" -e "</tool_call>"
.\examples\csharp\ModelChat\bin\Release\net8.0\ModelChat.exe -m test\test_models\qwen-2.5-0.5b\int4\cpu\ -e cpu --response_format lark_grammar --tools_file test\test_models\tool-definitions\weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
python3 test\python\special_tokens.py -p test\models\qwen-2.5-0.5b\int4\cpu\tokenizer.json -s "<tool_call>" -e "</tool_call>"
.\examples\csharp\ModelChat\bin\Release\net8.0\ModelChat.exe -m test\models\qwen-2.5-0.5b\int4\cpu\ -e cpu --response_format lark_grammar --tools_file test\models\tool-definitions\weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose

- name: Verify Build Artifacts
if: always()
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 @@ -125,7 +125,7 @@ jobs:

- name: Run the Python Tests
run: |
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\test_models"
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\models"

- name: Build the C# API and Run the C# Tests
run: |
Expand All @@ -141,8 +141,8 @@ jobs:

- name: Test the C# LLM Example with Tool Calling
run: |
python3 test\python\special_tokens.py -p test\test_models\qwen-2.5-0.5b\int4\cpu\tokenizer.json -s "<tool_call>" -e "</tool_call>"
.\examples\csharp\ModelChat\bin\Release\net8.0\ModelChat.exe -m test\test_models\qwen-2.5-0.5b\int4\cpu\ -e cpu --response_format lark_grammar --tools_file test\test_models\tool-definitions\weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
python3 test\python\special_tokens.py -p test\models\qwen-2.5-0.5b\int4\cpu\tokenizer.json -s "<tool_call>" -e "</tool_call>"
.\examples\csharp\ModelChat\bin\Release\net8.0\ModelChat.exe -m test\models\qwen-2.5-0.5b\int4\cpu\ -e cpu --response_format lark_grammar --tools_file test\models\tool-definitions\weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose

- name: Verify Build Artifacts
if: always()
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/win-cuda-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:

- name: Run the Python Tests
run: |
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\test_models" --e2e
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\models" --e2e

- name: Verify Build Artifacts
if: always()
Expand All @@ -182,8 +182,8 @@ jobs:

- name: Test the C# LLM Example with Tool Calling
run: |
python test\python\special_tokens.py -p test\test_models\qwen-2.5-0.5b\int4\cpu\tokenizer.json -s "<tool_call>" -e "</tool_call>"
.\examples\csharp\ModelChat\bin\Release\net8.0\ModelChat.exe -m test\test_models\qwen-2.5-0.5b\int4\cpu\ -e cpu --response_format lark_grammar --tools_file test\test_models\tool-definitions\weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
python test\python\special_tokens.py -p test\models\qwen-2.5-0.5b\int4\cpu\tokenizer.json -s "<tool_call>" -e "</tool_call>"
.\examples\csharp\ModelChat\bin\Release\net8.0\ModelChat.exe -m test\models\qwen-2.5-0.5b\int4\cpu\ -e cpu --response_format lark_grammar --tools_file test\models\tool-definitions\weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose

- name: Prepend CUDA to PATH and Run tests
run: |-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/win-directml-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

- name: Run the Python Tests
run: |
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\test_models" --e2e
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\models" --e2e

- name: Verify Build Artifacts
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/win-webgpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:

- name: Run the Python Tests
run: |
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\test_models" --e2e
python test/python/test_onnxruntime_genai.py --cwd "test\python" --test_models "test\models" --e2e

- name: Verify Build Artifacts
if: always()
Expand Down
31 changes: 12 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ src/csharp/AssemblyInfo.cs
/ort
/build
/build_*
/test/test_models/*
/test/models/*
/cache_models
/onnxruntime-linux-x64-*
*.csv
Expand All @@ -29,24 +29,17 @@ examples/python/genai_models
examples/python/hf_cache
examples/csharp/ModelChat/models

!test/test_models/hf-internal-testing/
!test/test_models/hf-internal-testing/tiny-random-gpt2*/*.onnx
!test/test_models/hf-internal-testing/tiny-qwen35-cuda/*.onnx
!test/test_models/grammars/
!test/test_models/qwen-vision-preprocessing/
!test/test_models/qwen-vision-preprocessing/*.onnx
!test/test_models/qwen3-vl-vision-preprocessing/
!test/test_models/qwen3-vl-vision-preprocessing/*.onnx
!test/test_models/qwen35-hybrid-preprocessing/
!test/test_models/qwen35-hybrid-preprocessing/*.onnx
!test/test_models/mistral3-vision-preprocessing/
!test/test_models/gemma4-vision-preprocessing/
!test/test_models/gemma4-vision-preprocessing/*.onnx
!test/test_models/multimodal-decoder-no-input-ids/
!test/test_models/multimodal-decoder-no-input-ids/*
!test/test_models/multimodal-decoder-with-input-ids/
!test/test_models/multimodal-decoder-with-input-ids/*
!test/test_models/create_decoder_input_ids_test_models.py
!test/models/gemma4/*
!test/models/hf-internal-testing/*
!test/models/mistral3/*
!test/models/multimodal-decoder-no-input-ids/*
!test/models/multimodal-decoder-with-input-ids/*
!test/models/phi3-v/*
!test/models/pipeline-model/*.json
!test/models/qwen2-5-vl/*
!test/models/qwen3-5/*
!test/models/qwen3-vl/*
!test/models/whisper/*

.ipynb_checkpoints/
/src/java/.gradle
Expand Down
6 changes: 3 additions & 3 deletions .pipelines/mac-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
source genai-macos-venv/bin/activate
export ORTGENAI_LOG_ORT_LIB=1
python3 -m pip install requests
python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models
python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/models
displayName: 'Run the Python tests'
workingDirectory: '$(Build.SourcesDirectory)'

Expand All @@ -233,8 +233,8 @@ jobs:
- bash: |
set -e -x
export ORTGENAI_LOG_ORT_LIB=1
python3 test/python/special_tokens.py -p test/test_models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>"
./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/test_models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/test_models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
python3 test/python/special_tokens.py -p test/models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>"
./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose
displayName: 'Test the C# LLM example with tool calling'
workingDirectory: '$(Build.SourcesDirectory)'

Expand Down
2 changes: 1 addition & 1 deletion examples/c/src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool ParseArgs(
app.add_option("-p,--top_p", generator_params_args.top_p, "Top p probability to sample with")->group(generator_params);

app.add_option("--response_format", guidance_args.response_format, "Provide response format for the model")->group(guidance);
app.add_option("--tools_file", guidance_args.tools_file, "Path to file containing list of OpenAI-compatible tool definitions. Ex: test/test_models/tool-definitions/weather.json")->group(guidance);
app.add_option("--tools_file", guidance_args.tools_file, "Path to file containing list of OpenAI-compatible tool definitions. Ex: test/models/tool-definitions/weather.json")->group(guidance);
app.add_flag("--text_output", guidance_args.text_output, "Produce a text response in the output")->group(guidance);
app.add_flag("--tool_output", guidance_args.tool_output, "Produce a tool call in the output")->group(guidance);
app.add_option("--tool_call_start", guidance_args.tool_call_start, "String representation of tool call start (ex: <|tool_call|>). Needs to be marked as special in tokenizer.json for guidance to work.")->group(guidance);
Expand Down
2 changes: 1 addition & 1 deletion examples/csharp/Common/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public static void GetGuidanceArgs(RootCommand parser)
{
Arity = ArgumentArity.ExactlyOne,
DefaultValueFactory = (_) => "",
Description = "Path to file containing list of OpenAI-compatible tool definitions. Ex: test/test_models/tool-definitions/weather.json"
Description = "Path to file containing list of OpenAI-compatible tool definitions. Ex: test/models/tool-definitions/weather.json"
};
tools_file.Validators.Add(result =>
{
Expand Down
2 changes: 1 addition & 1 deletion examples/python/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def get_guidance_args(parser: argparse.ArgumentParser) -> None:
"--tools_file",
type=str,
default="",
help="Path to file containing list of OpenAI-compatible tool definitions. Ex: test/test_models/tool-definitions/weather.json",
help="Path to file containing list of OpenAI-compatible tool definitions. Ex: test/models/tool-definitions/weather.json",
)
guidance.add_argument(
"-text", "--text_output", action="store_true", default=False, help="Produce a text response in the output"
Expand Down
2 changes: 1 addition & 1 deletion src/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ if (ANDROID)
# Copy the test model to the assets folder in the test app
add_custom_command(TARGET onnxruntime-genai-jni POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
${REPO_ROOT}/test/test_models/hf-internal-testing/tiny-random-gpt2-fp32
${REPO_ROOT}/test/models/hf-internal-testing/tiny-random-gpt2-fp32
${ANDROID_TEST_PACKAGE_APP_ASSETS_DIR}/model)

# Copy the Android AAR package we built to the libs folder of our test app
Expand Down
2 changes: 1 addition & 1 deletion src/java/src/test/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This directory contains a simple android application for testing the ONNX Runtim

This android application is mainly aimed for testing:

- Model used: test/test_models/hf-internal-testing/tiny-random-gpt2-fp32
- Model used: test/models/hf-internal-testing/tiny-random-gpt2-fp32
- Main test file: An android instrumentation test under `app\src\androidtest\java\ai.onnxruntime.genai.example.javavalidator\SimpleTest.kt`
- The main dependency of this application is `onnxruntime-genai` aar package under `app\libs`.
- The onnxruntime dependency is provided by the latest released onnxruntime-android package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GenerationTest {
// phi-2 can be used in full end-to-end testing but needs to be manually downloaded.
// it's also used this way in the C# unit tests.
private static final String phi2ModelPath() {
return TestUtils.getTestResourcePath("phi-2/int4/cpu");
return TestUtils.getTestModelPath("phi-2/int4/cpu");
}

@SuppressWarnings("unused") // Used in EnabledIf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public void testBatchEncodeDecode() throws GenAIException {
new String(
"<|user|>\n<|image_1|>\n Can you convert the table to markdown format?\n<|end|>\n<|assistant|>\n");
try (Images image =
new Images(
TestUtils.getFilePathFromDisk(
TestUtils.getTestResourcePath("images/sheet.png")));
new Images(TestUtils.getFilePathFromDisk(TestUtils.getTestImagePath("sheet.png")));
NamedTensors processed = multiModalProcessor.processImages(inputs, image); ) {
assertNotNull(processed);
}
Expand Down
Loading
Loading