Skip to content

Commit 4b9a100

Browse files
committed
doc
1 parent c3c9efb commit 4b9a100

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

onnx_diagnostic/helpers/mini_onnx_builder.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,27 @@ def create_onnx_model_from_input_tensors(
422422
:return: ModelProto
423423
424424
The function raises an error if not supported.
425+
An example:
426+
427+
.. code-block:: python
428+
429+
from onnx_diagnostic.helpers.mini_onnx_builder import (
430+
create_onnx_model_from_input_tensors,
431+
)
432+
import onnx
433+
434+
proto = create_onnx_model_from_input_tensors(
435+
dict(
436+
query_states=query_states,
437+
key_states=key_states,
438+
value_states=value_states,
439+
cu_seqlens=cu_seqlens,
440+
max_seqlen=(cu_seqlens[1:] - cu_seqlens[:-1]).max(),
441+
scaling=self.scaling,
442+
attn_output=attn_output,
443+
)
444+
)
445+
onnx.save(proto, "attention_inputs.onnx")
425446
"""
426447
if switch_low_high is None:
427448
switch_low_high = sys.byteorder != "big"
@@ -567,6 +588,19 @@ def create_input_tensors_from_onnx_model(
567588
:return: restored data
568589
569590
See example :ref:`l-plot-intermediate-results` for an example.
591+
592+
.. code-bloc:: python
593+
594+
import os
595+
from onnx_diagnostic.helpers.mini_onnx_builder import (
596+
create_input_tensors_from_onnx_model,
597+
)
598+
from onnx_diagnostic.helpers import string_type
599+
600+
restored = create_input_tensors_from_onnx_model("attention_inputs.onnx")
601+
for k, v in restored.items():
602+
print(f"{k}: {string_type(v, with_shape=True, with_min_max=True)}")
603+
570604
"""
571605
if engine == "ExtendedReferenceEvaluator":
572606
from ..reference import ExtendedReferenceEvaluator

0 commit comments

Comments
 (0)