CodeSampleX

Sample

onnxruntime 1.28.0: OrtValue

Verified sample for pypi onnxruntime 1.28.0: OrtValue. The contract ran on python 3.12 · linux debian/x64 · docker and passed.

sha256:4932484bb0f902eed191a61a97518dc88318a0523af59bfcf6e5adb02d442f6e

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip 24

Verification-run environments

Environment Contract Stages Run
python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104…
2026-09-07

Case

HOW
Goal
verify onnxruntime.OrtValue in pkg:pypi/onnxruntime@1.28.0
Packages
Symbols
  • onnxruntime.OrtValue
Environment
python 3.12
Created
2026-09-07T04:16:18Z

Contract

  1. OrtValue.ortvalue_from_numpy wraps NumPy array into tensor OrtValue preserving shape, dtype, and device
  2. OrtValue.numpy extracts underlying NumPy array matching original array data and type
  3. OrtValue.data_type identifies tensor element types including float, double, int32, int64, and bool
  4. OrtValue.ortvalue_from_shape_and_type allocates uninitialized tensor buffer of specified shape and element type
  5. IOBinding.bind_ortvalue_input binds OrtValue instances directly to session graph inputs
  6. IOBinding.get_outputs returns OrtValue instances containing model execution results

Files

  • PROMPT.md
  • csx.json
  • pyproject.toml
  • requirements.txt
  • spec.json
  • test/contract.py

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify onnxruntime.OrtValue in pkg:pypi/onnxruntime@1.28.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/onnxruntime@1.28.0
Demonstrate these symbols/APIs:
  - onnxruntime.OrtValue

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:bd04b4fa95f734239cb0344b4d4ea60bab3c56ea1a7f4730675046ae7c9faf28","constraints":{"executionContext":"python"},"contract":["OrtValue.ortvalue_from_numpy wraps NumPy array into tensor OrtValue preserving shape, dtype, and device","OrtValue.numpy extracts underlying NumPy array matching original array data and type","OrtValue.data_type identifies tensor element types including float, double, int32, int64, and bool","OrtValue.ortvalue_from_shape_and_type allocates uninitialized tensor buffer of specified shape and element type","IOBinding.bind_ortvalue_input binds OrtValue instances directly to session graph inputs","IOBinding.get_outputs returns OrtValue instances containing model execution results"],"goal":"verify onnxruntime.OrtValue in pkg:pypi/onnxruntime@1.28.0","kind":"HOW","packages":["pkg:pypi/onnxruntime@1.28.0"],"schemaVersion":1,"symbols":["onnxruntime.OrtValue"]},"contractCommand":["python3","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","moduleSystem":"standard","os":"linux","osVersionBucket":"24","packageManager":"pip","packageManagerVersion":"24.0","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/onnxruntime@1.28.0"],"schemaVersion":1,"subject":"pkg:pypi/onnxruntime@1.28.0","symbols":["onnxruntime.OrtValue"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-onnxruntime-ortvalue"
version = "0.1.0"
dependencies = [
    "flatbuffers==25.12.19",
    "numpy==2.5.2",
    "onnxruntime==1.28.0",
    "packaging==26.3",
    "protobuf==7.36.0",
]
requirements.txt
flatbuffers==25.12.19
numpy==2.5.2
onnxruntime==1.28.0
packaging==26.3
protobuf==7.36.0
spec.json
{
  "schemaVersion": 1,
  "goal": "verify onnxruntime.OrtValue in pkg:pypi/onnxruntime@1.28.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/onnxruntime@1.28.0"
  ],
  "symbols": [
    "onnxruntime.OrtValue"
  ]
}
test/contract.py
import numpy as np
import onnxruntime as ort

# A minimal, valid 106-byte Add model (Y = X + W) with shape [?, 3] float32
MODEL_BYTES = bytes.fromhex(
    "080d120a6373782d73616d706c653a540a0e0a01580a0157120159220341646412096164645f"
    "67726170685a110a0158120c0a0a080112060a000a0208035a110a0157120c0a0a080112060a"
    "000a02080362110a0159120c0a0a080112060a000a02080342040a00100e"
)


def test_ortvalue_from_numpy():
    arr = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=np.float32)
    ort_val = ort.OrtValue.ortvalue_from_numpy(arr)

    assert ort_val.is_tensor() is True
    assert ort_val.shape() == [2, 3]
    assert ort_val.data_type() == "tensor(float)"
    assert ort_val.device_name().lower() == "cpu"
    np.testing.assert_allclose(ort_val.numpy(), arr)


def test_ortvalue_data_types():
    # int64
    arr_i64 = np.array([10, 20, 30], dtype=np.int64)
    ort_i64 = ort.OrtValue.ortvalue_from_numpy(arr_i64)
    assert ort_i64.data_type() == "tensor(int64)"
    assert ort_i64.shape() == [3]
    np.testing.assert_array_equal(ort_i64.numpy(), arr_i64)

    # int32
    arr_i32 = np.array([[1, 2], [3, 4]], dtype=np.int32)
    ort_i32 = ort.OrtValue.ortvalue_from_numpy(arr_i32)
    assert ort_i32.data_type() == "tensor(int32)"
    assert ort_i32.shape() == [2, 2]
    np.testing.assert_array_equal(ort_i32.numpy(), arr_i32)

    # bool
    arr_bool = np.array([True, False, True], dtype=bool)
    ort_bool = ort.OrtValue.ortvalue_from_numpy(arr_bool)
    assert ort_bool.data_type() == "tensor(bool)"
    np.testing.assert_array_equal(ort_bool.numpy(), arr_bool)

    # float64
    arr_f64 = np.array([1.5, 2.5, 3.5], dtype=np.float64)
    ort_f64 = ort.OrtValue.ortvalue_from_numpy(arr_f64)
    assert ort_f64.data_type() == "tensor(double)"
    np.testing.assert_allclose(ort_f64.numpy(), arr_f64)


def test_ortvalue_from_shape_and_type():
    shape = [3, 4]
    ort_val = ort.OrtValue.ortvalue_from_shape_and_type(shape, np.float32)

    assert ort_val.is_tensor() is True
    assert ort_val.shape() == shape
    assert ort_val.data_type() == "tensor(float)"
    assert ort_val.numpy().shape == tuple(shape)


def test_ortvalue_in_session_iobinding():
    session = ort.InferenceSession(MODEL_BYTES, providers=["CPUExecutionProvider"])
    io_binding = session.io_binding()

    x_arr = np.array([[1.0, 2.0, 3.0]], dtype=np.float32)
    w_arr = np.array([[10.0, 20.0, 30.0]], dtype=np.float32)

    x_ort = ort.OrtValue.ortvalue_from_numpy(x_arr)
    w_ort = ort.OrtValue.ortvalue_from_numpy(w_arr)

    io_binding.bind_ortvalue_input("X", x_ort)
    io_binding.bind_ortvalue_input("W", w_ort)
    io_binding.bind_output("Y")

    session.run_with_iobinding(io_binding)

    outputs = io_binding.get_outputs()
    assert len(outputs) == 1
    out_ort = outputs[0]

    assert isinstance(out_ort, ort.OrtValue)
    assert out_ort.is_tensor() is True
    assert out_ort.shape() == [1, 3]
    assert out_ort.data_type() == "tensor(float)"
    np.testing.assert_allclose(out_ort.numpy(), np.array([[11.0, 22.0, 33.0]], dtype=np.float32))


def main():
    test_ortvalue_from_numpy()
    test_ortvalue_data_types()
    test_ortvalue_from_shape_and_type()
    test_ortvalue_in_session_iobinding()
    print("All onnxruntime.OrtValue contract assertions passed.")


if __name__ == "__main__":
    main()

Origin Seeder

anonymous