Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.dot
*.dylib
*.ep
*.ep.graph
*.prof
*.pyc
*.pyd
Expand All @@ -9,6 +11,7 @@
*.c
.build_path.txt
*.onnx
*.xlsx
plot*.png
plot*.csv
plot*.xlsx
Expand Down
6 changes: 0 additions & 6 deletions _doc/articles/2024-05-31-route2024-gpu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ Optimize a machine learning model by fusing operations.
pip install -U huggingface_hub
huggingface-cli download alpindale/Llama-2-7b-ONNX --repo-type model --cache-dir cache --local-dir . --local-dir-use-symlinks False

Or:

::

python -m experimental_experiment.torch_bench.export_model --model llama --mixed 1 --exporter script --config small --num_hidden_layer 2

.. image:: images/netron.png

One part of the llama model:
Expand Down
9 changes: 4 additions & 5 deletions _doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,21 @@
mathjax3_config = {"chtml": {"displayAlign": "left"}}

intersphinx_mapping = {
"experimental_experiment": (
"https://sdpython.github.io/doc/experimental-experiment/dev/",
None,
),
"IPython": ("https://ipython.readthedocs.io/en/stable/", None),
"matplotlib": ("https://matplotlib.org/", None),
"numpy": ("https://numpy.org/doc/stable", None),
"onnx": ("https://onnx.ai/onnx/", None),
"onnx_array_api": ("https://sdpython.github.io/doc/onnx-array-api/dev/", None),
"onnx_diagnostic": ("https://sdpython.github.io/doc/onnx-diagnostic/dev/", None),
"onnx_extended": ("https://sdpython.github.io/doc/onnx-extended/dev/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"python": (f"https://docs.python.org/{sys.version_info.major}", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
"torch": ("https://pytorch.org/docs/stable/", None),
"yobx": (
"https://sdpython.github.io/doc/yet-another-onnx-builder/dev/",
None,
),
}

# Check intersphinx reference targets exist
Expand Down
1 change: 0 additions & 1 deletion _doc/examples/plot_benchmark_dot_mul_timeit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
c_multiply_matrix_parallel_transposed as cmulparamtr,
)


va = numpy.random.randn(150, 100).astype(numpy.float64)
vb = numpy.random.randn(100, 100).astype(numpy.float64)
ctx = {
Expand Down
13 changes: 10 additions & 3 deletions _doc/examples/plot_export_model_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,17 @@ def generate_example_inputs(batch: int, seq: int, vocab_size: int):


def export(model, args, filename, dynamic_shapes):
from experimental_experiment.torch_interpreter import to_onnx, ExportOptions
from onnx_diagnostic.torch_export_patches import bypass_export_some_errors
from yobx.torch import (
to_onnx,
ExportOptions,
apply_patches_for_model,
register_flattening_functions,
)

with bypass_export_some_errors(patch_transformers=True):
with (
register_flattening_functions(patch_transformers=True),
apply_patches_for_model(patch_transformers=True, model=model),
):
to_onnx(
model,
args,
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_serialisation_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Ecriture (json)
+++++++++++++++
"""

from io import StringIO, BytesIO
import timeit
import json
Expand All @@ -25,7 +26,6 @@
import matplotlib.pyplot as plt
import pandas


data = {
"records": [
{
Expand Down
46 changes: 46 additions & 0 deletions _tutoriels/nanobind/dotnanobind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <memory>
#include <omp.h> // <- OpenMP

namespace nb = nanobind;

using Array1D = nb::ndarray<double, nb::ndim<1>, nb::c_contig, nb::device::cpu>;

nb::ndarray<nb::numpy, double, nb::ndim<1>> add_scaled_omp(Array1D a, Array1D b) {
size_t n = a.shape(0);
const double *pa = a.data();
const double *pb = b.data();

auto result = std::make_unique<double[]>(n);

#pragma omp parallel for
for (size_t i = 0; i < n; ++i) {
result[i] = pa[i] + 2.0 * pb[i];
}

double *raw = result.release();
nb::capsule owner(raw, [](void *p) noexcept { delete[] (double *)p; });
size_t shape[1] = {n};
return nb::ndarray<nb::numpy, double, nb::ndim<1>>(raw, 1, shape, owner);
}

double dot_product_omp(Array1D a, Array1D b) {
size_t n = a.shape(0);
const double *pa = a.data();
const double *pb = b.data();

double total = 0.0;

#pragma omp parallel for reduction(+:total)
for (size_t i = 0; i < n; ++i) {
total += pa[i] * pb[i];
}

return total;
}

NB_MODULE(dotnanobind, m) {
m.def("add_scaled", &add_scaled_omp, "Add a + 2*b using OpenMP");
m.def("dot_product", &dot_product_omp, "Dot product using OpenMP");
}
35 changes: 35 additions & 0 deletions _tutoriels/nanobind/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path

from setuptools import Extension, setup

import nanobind

# Compiler flags for OpenMP
extra_compile_args = ["-O3", "-fopenmp", "-std=c++17", "-fvisibility=hidden"]
extra_link_args = ["-fopenmp"]

nb_include = nanobind.include_dir()
nb_src = Path(nanobind.source_dir()) / "nb_combined.cpp"
# nanobind bundles tsl/robin_map, needed when building nb_combined.cpp directly
nb_ext_include = str(
Path(nanobind.include_dir()).parent / "ext" / "robin_map" / "include"
)

ext_modules = [
Extension(
"dotnanobind",
sources=["dotnanobind.cpp", str(nb_src)],
include_dirs=[nb_include, nb_ext_include],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
),
]

setup(
name="dotnanobind",
version="0.1",
author="Ton Nom",
description="Nanobind + OpenMP dotnanobind",
ext_modules=ext_modules,
zip_safe=False,
)
1 change: 0 additions & 1 deletion _unittests/ut_xrun_doc/test_documentation_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from teachcompute import __file__ as teachcompute_file, has_cuda
from teachcompute.ext_test_case import ExtTestCase, has_transformers, is_apple


VERBOSE = 0
ROOT = os.path.realpath(os.path.abspath(os.path.join(teachcompute_file, "..", "..")))

Expand Down
7 changes: 4 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ coverage
cython>=3.0.10
cython-lint
cytoolz
git+https://github.com/sdpython/experimental-experiment.git; sys_platform != 'darwin'
git+https://github.com/xadupre/yet-another-onnx-builder.git; sys_platform != 'darwin'
furo
ipython
joblib
Expand All @@ -17,8 +17,9 @@ mypy
nbsphinx
numba
onnx
onnx-diagnostic>=0.3.0
onnxscript
openpyxl
optree
pandas
pillow
protobuf
Expand All @@ -28,7 +29,7 @@ pytest
pytest-cov
torchaudio
torchvision
transformers>=4.49; sys_platform != 'darwin'
transformers>=5.3; sys_platform != 'darwin'
ruff
sphinx
sphinx-gallery
Expand Down
Loading