yobx.torch.patch#

yobx.torch.patch.apply_patches_for_model(patch_torch: bool = False, patch_transformers: bool = False, verbose: int = 0, model: Module | None = None) Generator[PatchDetails, None, None][source]#

The context manager apply patches, usually before exporting a model.

from yobx.torch import apply_patches_for_model

with apply_patches_for_model(patch_transformers=True, model=model):
    # ...
Parameters:
  • patch_torch – applies patches for torch

  • patch_transformers – applies patch for transformers

  • verbose – prints out which patch is applies

  • model – modifies the list of patches for a particular model, it is recommended to fill it the used rope is not the default one

The following shows how to use the output of this function to display information about the patches applied to the model.

from yobx.torch import apply_patches_for_model

with apply_patches_for_model(patch_transformers=True, model=model) as details:
    for patch in details:
        diff = patch.make_diff()
        print(f"-- patch {patch!r}")
        print(diff)
yobx.torch.patch.retrieve_stacktrace()[source]#

Retrieves and prints the current stack trace, avoids every torch file.