o
     i}
                     @   s   d dl mZmZmZmZ d dlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ed dfe	ddfe
dd	fed	d
ffZdefdedeej deeeeef  fddZdddZdS )    )AnyOptionalSequenceTupleN   )MemSnapshotsProfilerNsightProfilerPyTorchProfilerPyTorchProfiler_CUDAOnly	_Profiler)DCGMProfiler               
output_dirmoduleschedulec                 C   s   t | ||dS )a  
    A pre-configured profiler that will run on the first ~20 steps of the training
    It will provide multiple traces that can be exploited later.
    Use it in a context manager around your training loop, and call `xformers.profiler.step`
    before starting the next iteration.

    :Examples:

    .. code-block:: python

        import torch
        import timm.models
        import xformers.profiler

        dtype = torch.bfloat16
        device = "cuda"
        model = timm.models.vit_large_patch16_224().to(device).to(dtype)
        inp = torch.zeros([64, 3, 224, 224], device=device, dtype=dtype)
        optim = torch.optim.Adam(model.parameters())

        with xformers.profiler.profile(
            output_dir="profile_data",
            module=model,
            schedule=[
                (MemSnapshotsProfiler, 0, 2),
                (NsightProfiler, 4, 6),
                (PyTorchProfiler, 6, 20),
            ]
        ):
            for i in range(20):
                model(inp).sum().backward()
                optim.step()
                optim.zero_grad()
                xformers.profiler.step()

        # alternatively, use the profiler without context and with ``.start()`` / `.stop()`
        # calls.

        xprofiler = xformers.profiler.profile(...)
        xprofiler.start()

        for i in range(20):
            model(inp).sum().backward()
            optim.step()
            optim.zero_grad()
            xprofiler.step()

        xprofiler.stop()
    )r   r   r   )r   )r   r   r    r   I/home/ubuntu/.local/lib/python3.10/site-packages/xformers/profiler/api.pyprofile   s   6r   returnc                   C   s   t jdu rdS t j  dS )zSee `xformers.profiler.profile`N)r   _CURRENT_PROFILERstepr   r   r   r   r   W   s   
r   )r   N)typingr   r   r   r   torch.nnnnprofilerr   r   r	   r
   r   profiler_dcgmr   DEFAULT_SCHEDULEstrModuleintr   r   r   r   r   r   <module>   s&   
9