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
11 changes: 9 additions & 2 deletions _doc/patches.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Function :func:`onnx_diagnostic.torch_export_patches.torch_export_patches`
implements four kinds of patches to make it easier to export a model, usually
coming from :epkg:`transformers`.
All patches takes place in :mod:`onnx_diagnostic.torch_export_patches`.

.. code-block:: python

with torch_export_patches(...) as f:
Expand Down Expand Up @@ -121,13 +122,19 @@ requires the following value for parameter ``rewrite``:
.. runpython::
:showcode:

import pprint
from onnx_diagnostic.torch_export_patches.patch_module_helper import (
code_needing_rewriting,
)

print(code_needing_rewriting("BartForConditionalGeneration"))
pprint.pprint(code_needing_rewriting("BartForConditionalGeneration"))

And that produces:
This method has two tests. Only the first one needs to be rewritten.
The second one manipulates tuple and the automated rewritten does not handle
that because it cannot detect types. That explains why the parameter
``filter_node`` is filled. Then, the first test includes a condition relying on ``or``
which must be replaced by ``|``. That explains the parameter ``pre_rewriter``.
We finally get:

.. code-block:: diff

Expand Down
3 changes: 2 additions & 1 deletion onnx_diagnostic/torch_export_patches/patch_module_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ def code_needing_rewriting(cls_name: str) -> Optional[List[Any]]:
.. runpython::
:showcode:
import pprint
from onnx_diagnostic.torch_export_patches.patch_module_helper import (
code_needing_rewriting,
)
print(code_needing_rewriting("BartForConditionalGeneration"))
pprint.pprint(code_needing_rewriting("BartForConditionalGeneration"))
"""
if cls_name in {
"BartEncoderLayer",
Expand Down
Loading