Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lib/python3.12/site-packages/_multiprocess/__init__.pyAdded+8
- lib/python3.12/site-packages/_multiprocess/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/big_modeling.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/checkpointing.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/data_loader.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/hooks.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/inference.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/launchers.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/local_sgd.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/logging.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/memory_utils.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/optimizer.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/scheduler.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/state.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/__pycache__/tracking.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/test_utils/scripts/__pycache__/test_cli.cpython-312.pycAdded
- lib/python3.12/site-packages/accelerate/test_utils/scripts/__pycache__/test_script.cpython-312.pycAdded
- lib/python3.12/site-packages/blinker/__init__.pyAdded+17
- lib/python3.12/site-packages/blinker/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/blinker/__pycache__/_utilities.cpython-312.pycAdded
- lib/python3.12/site-packages/blinker/__pycache__/base.cpython-312.pycAdded
- lib/python3.12/site-packages/blinker/_utilities.pyAdded+64
- lib/python3.12/site-packages/blinker/base.pyAdded+512
- lib/python3.12/site-packages/blinker/py.typedAdded
- lib/python3.12/site-packages/einops-0.8.2.dist-info/INSTALLERAdded+1
- lib/python3.12/site-packages/einops-0.8.2.dist-info/METADATAAdded+394
- lib/python3.12/site-packages/einops-0.8.2.dist-info/RECORDAdded+58
- lib/python3.12/site-packages/einops-0.8.2.dist-info/WHEELAdded+4
- lib/python3.12/site-packages/einops-0.8.2.dist-info/licenses/LICENSEAdded+21
- lib/python3.12/site-packages/functorch/__init__.pyAdded+39
- lib/python3.12/site-packages/functorch/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/_src/__init__.pyAdded
- lib/python3.12/site-packages/functorch/_src/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/_src/aot_autograd/__init__.pyAdded+8
- lib/python3.12/site-packages/functorch/_src/aot_autograd/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/_src/eager_transforms/__init__.pyAdded+7
- lib/python3.12/site-packages/functorch/_src/eager_transforms/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/_src/make_functional/__init__.pyAdded+4
- lib/python3.12/site-packages/functorch/_src/make_functional/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/_src/vmap/__init__.pyAdded+16
- lib/python3.12/site-packages/functorch/_src/vmap/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/compile/__init__.pyAdded+30
- lib/python3.12/site-packages/functorch/compile/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/dim/__init__.pyAdded+181
- lib/python3.12/site-packages/functorch/dim/__pycache__/__init__.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/dim/__pycache__/batch_tensor.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/dim/__pycache__/delayed_mul_tensor.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/dim/__pycache__/dim.cpython-312.pycAdded
- lib/python3.12/site-packages/functorch/dim/__pycache__/magic_trace.cpython-312.pycAdded
12345678#!/usr/bin/env python## Author: Mike McKerns (mmckerns @caltech and @uqfoundation)# Copyright (c) 2022-2024 The Uncertainty Quantification Foundation.# License: 3-clause BSD. The full license text is available at:# - https://github.com/uqfoundation/multiprocess/blob/master/LICENSE
from _multiprocessing import *1234567891011121314151617from __future__ import annotations
from .base import ANYfrom .base import default_namespacefrom .base import NamedSignalfrom .base import Namespacefrom .base import Signalfrom .base import signal
__all__ = [ "ANY", "default_namespace", "NamedSignal", "Namespace", "Signal", "signal",]12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364from __future__ import annotations
import collections.abc as cimport inspectimport typing as tfrom weakref import reffrom weakref import WeakMethod
T = t.TypeVar("T")
class Symbol: """A constant symbol, nicer than ``object()``. Repeated calls return the same instance.
>>> Symbol('foo') is Symbol('foo') True >>> Symbol('foo') foo """
symbols: t.ClassVar[dict[str, Symbol]] = {}
def __new__(cls, name: str) -> Symbol: if name in cls.symbols: return cls.symbols[name]
obj = super().__new__(cls) cls.symbols[name] = obj return obj
def __init__(self, name: str) -> None: self.name = name
def __repr__(self) -> str: return self.name
def __getnewargs__(self) -> tuple[t.Any, ...]: return (self.name,)
def make_id(obj: object) -> c.Hashable: """Get a stable identifier for a receiver or sender, to be used as a dict key or in a set. """ if inspect.ismethod(obj): # The id of a bound method is not stable, but the id of the unbound # function and instance are. return id(obj.__func__), id(obj.__self__)
if isinstance(obj, (str, int)): # Instances with the same value always compare equal and have the same # hash, even if the id may change. return obj
# Assume other types are not hashable but will always be the same instance. return id(obj)
def make_ref(obj: T, callback: c.Callable[[ref[T]], None] | None = None) -> ref[T]: if inspect.ismethod(obj): return WeakMethod(obj, callback) # type: ignore[arg-type, return-value]
return ref(obj, callback)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512from __future__ import annotations
import collections.abc as cimport sysimport typing as timport weakreffrom collections import defaultdictfrom contextlib import contextmanagerfrom functools import cached_propertyfrom inspect import iscoroutinefunction
from ._utilities import make_idfrom ._utilities import make_reffrom ._utilities import Symbol
F = t.TypeVar("F", bound=c.Callable[..., t.Any])
ANY = Symbol("ANY")"""Symbol for "any sender"."""
ANY_ID = 0
class Signal: """A notification emitter.
:param doc: The docstring for the signal. """
ANY = ANY """An alias for the :data:`~blinker.ANY` sender symbol."""
set_class: type[set[t.Any]] = set """The set class to use for tracking connected receivers and senders. Python's ``set`` is unordered. If receivers must be dispatched in the order they were connected, an ordered set implementation can be used.
.. versionadded:: 1.7 """
@cached_property def receiver_connected(self) -> Signal: """Emitted at the end of each :meth:`connect` call.
The signal sender is the signal instance, and the :meth:`connect` arguments are passed through: ``receiver``, ``sender``, and ``weak``.
.. versionadded:: 1.2 """ return Signal(doc="Emitted after a receiver connects.")
@cached_property def receiver_disconnected(self) -> Signal: """Emitted at the end of each :meth:`disconnect` call.
The sender is the signal instance, and the :meth:`disconnect` arguments are passed through: ``receiver`` and ``sender``.
This signal is emitted **only** when :meth:`disconnect` is called explicitly. This signal cannot be emitted by an automatic disconnect when a weakly referenced receiver or sender goes out of scope, as the instance is no longer be available to be used as the sender for this signal.
An alternative approach is available by subscribing to :attr:`receiver_connected` and setting up a custom weakref cleanup callback on weak receivers and senders.
.. versionadded:: 1.2 """ return Signal(doc="Emitted after a receiver disconnects.")
def __init__(self, doc: str | None = None) -> None: if doc: self.__doc__ = doc
self.receivers: dict[ t.Any, weakref.ref[c.Callable[..., t.Any]] | c.Callable[..., t.Any] ] = {} """The map of connected receivers. Useful to quickly check if any receivers are connected to the signal: ``if s.receivers:``. The structure and data is not part of the public API, but checking its boolean value is. """
self.is_muted: bool = False self._by_receiver: dict[t.Any, set[t.Any]] = defaultdict(self.set_class) self._by_sender: dict[t.Any, set[t.Any]] = defaultdict(self.set_class) self._weak_senders: dict[t.Any, weakref.ref[t.Any]] = {}
def connect(self, receiver: F, sender: t.Any = ANY, weak: bool = True) -> F: """Connect ``receiver`` to be called when the signal is sent by ``sender``.
:param receiver: The callable to call when :meth:`send` is called with the given ``sender``, passing ``sender`` as a positional argument along with any extra keyword arguments. :param sender: Any object or :data:`ANY`. ``receiver`` will only be called when :meth:`send` is called with this sender. If ``ANY``, the receiver will be called for any sender. A receiver may be connected to multiple senders by calling :meth:`connect` multiple times. :param weak: Track the receiver with a :mod:`weakref`. The receiver will be automatically disconnected when it is garbage collected. When connecting a receiver defined within a function, set to ``False``, otherwise it will be disconnected when the function scope ends. """ receiver_id = make_id(receiver) sender_id = ANY_ID if sender is ANY else make_id(sender)
if weak: self.receivers[receiver_id] = make_ref( receiver, self._make_cleanup_receiver(receiver_id) ) else: self.receivers[receiver_id] = receiver
self._by_sender[sender_id].add(receiver_id) self._by_receiver[receiver_id].add(sender_id)
if sender is not ANY and sender_id not in self._weak_senders: # store a cleanup for weakref-able senders try: self._weak_senders[sender_id] = make_ref( sender, self._make_cleanup_sender(sender_id) ) except TypeError: pass
if "receiver_connected" in self.__dict__ and self.receiver_connected.receivers: try: self.receiver_connected.send( self, receiver=receiver, sender=sender, weak=weak ) except TypeError: # TODO no explanation or test for this self.disconnect(receiver, sender) raise
return receiver
def connect_via(self, sender: t.Any, weak: bool = False) -> c.Callable[[F], F]: """Connect the decorated function to be called when the signal is sent by ``sender``.
The decorated function will be called when :meth:`send` is called with the given ``sender``, passing ``sender`` as a positional argument along with any extra keyword arguments.
:param sender: Any object or :data:`ANY`. ``receiver`` will only be called when :meth:`send` is called with this sender. If ``ANY``, the receiver will be called for any sender. A receiver may be connected to multiple senders by calling :meth:`connect` multiple times. :param weak: Track the receiver with a :mod:`weakref`. The receiver will be automatically disconnected when it is garbage collected. When connecting a receiver defined within a function, set to ``False``, otherwise it will be disconnected when the function scope ends.=
.. versionadded:: 1.1 """
def decorator(fn: F) -> F: self.connect(fn, sender, weak) return fn
return decorator
@contextmanager def connected_to( self, receiver: c.Callable[..., t.Any], sender: t.Any = ANY ) -> c.Generator[None, None, None]: """A context manager that temporarily connects ``receiver`` to the signal while a ``with`` block executes. When the block exits, the receiver is disconnected. Useful for tests.
:param receiver: The callable to call when :meth:`send` is called with the given ``sender``, passing ``sender`` as a positional argument along with any extra keyword arguments. :param sender: Any object or :data:`ANY`. ``receiver`` will only be called when :meth:`send` is called with this sender. If ``ANY``, the receiver will be called for any sender.
.. versionadded:: 1.1 """ self.connect(receiver, sender=sender, weak=False)
try: yield None finally: self.disconnect(receiver)
@contextmanager def muted(self) -> c.Generator[None, None, None]: """A context manager that temporarily disables the signal. No receivers will be called if the signal is sent, until the ``with`` block exits. Useful for tests. """ self.is_muted = True
try: yield None finally: self.is_muted = False
def send( self, sender: t.Any | None = None, /, *, _async_wrapper: c.Callable[ [c.Callable[..., c.Coroutine[t.Any, t.Any, t.Any]]], c.Callable[..., t.Any] ] | None = None, **kwargs: t.Any, ) -> list[tuple[c.Callable[..., t.Any], t.Any]]: """Call all receivers that are connected to the given ``sender`` or :data:`ANY`. Each receiver is called with ``sender`` as a positional argument along with any extra keyword arguments. Return a list of ``(receiver, return value)`` tuples.
The order receivers are called is undefined, but can be influenced by setting :attr:`set_class`.
If a receiver raises an exception, that exception will propagate up. This makes debugging straightforward, with an assumption that correctly implemented receivers will not raise.
:param sender: Call receivers connected to this sender, in addition to those connected to :data:`ANY`. :param _async_wrapper: Will be called on any receivers that are async coroutines to turn them into sync callables. For example, could run the receiver with an event loop. :param kwargs: Extra keyword arguments to pass to each receiver.
.. versionchanged:: 1.7 Added the ``_async_wrapper`` argument. """ if self.is_muted: return []
results = []
for receiver in self.receivers_for(sender): if iscoroutinefunction(receiver): if _async_wrapper is None: raise RuntimeError("Cannot send to a coroutine function.")
result = _async_wrapper(receiver)(sender, **kwargs) else: result = receiver(sender, **kwargs)
results.append((receiver, result))
return results
async def send_async( self, sender: t.Any | None = None, /, *, _sync_wrapper: c.Callable[ [c.Callable[..., t.Any]], c.Callable[..., c.Coroutine[t.Any, t.Any, t.Any]] ] | None = None, **kwargs: t.Any, ) -> list[tuple[c.Callable[..., t.Any], t.Any]]: """Await all receivers that are connected to the given ``sender`` or :data:`ANY`. Each receiver is called with ``sender`` as a positional argument along with any extra keyword arguments. Return a list of ``(receiver, return value)`` tuples.
The order receivers are called is undefined, but can be influenced by setting :attr:`set_class`.
If a receiver raises an exception, that exception will propagate up. This makes debugging straightforward, with an assumption that correctly implemented receivers will not raise.
:param sender: Call receivers connected to this sender, in addition to those connected to :data:`ANY`. :param _sync_wrapper: Will be called on any receivers that are sync callables to turn them into async coroutines. For example, could call the receiver in a thread. :param kwargs: Extra keyword arguments to pass to each receiver.
.. versionadded:: 1.7 """ if self.is_muted: return []
results = []
for receiver in self.receivers_for(sender): if not iscoroutinefunction(receiver): if _sync_wrapper is None: raise RuntimeError("Cannot send to a non-coroutine function.")
result = await _sync_wrapper(receiver)(sender, **kwargs) else: result = await receiver(sender, **kwargs)
results.append((receiver, result))
return results
def has_receivers_for(self, sender: t.Any) -> bool: """Check if there is at least one receiver that will be called with the given ``sender``. A receiver connected to :data:`ANY` will always be called, regardless of sender. Does not check if weakly referenced receivers are still live. See :meth:`receivers_for` for a stronger search.
:param sender: Check for receivers connected to this sender, in addition to those connected to :data:`ANY`. """ if not self.receivers: return False
if self._by_sender[ANY_ID]: return True
if sender is ANY: return False
return make_id(sender) in self._by_sender
def receivers_for( self, sender: t.Any ) -> c.Generator[c.Callable[..., t.Any], None, None]: """Yield each receiver to be called for ``sender``, in addition to those to be called for :data:`ANY`. Weakly referenced receivers that are not live will be disconnected and skipped.
:param sender: Yield receivers connected to this sender, in addition to those connected to :data:`ANY`. """ # TODO: test receivers_for(ANY) if not self.receivers: return
sender_id = make_id(sender)
if sender_id in self._by_sender: ids = self._by_sender[ANY_ID] | self._by_sender[sender_id] else: ids = self._by_sender[ANY_ID].copy()
for receiver_id in ids: receiver = self.receivers.get(receiver_id)
if receiver is None: continue
if isinstance(receiver, weakref.ref): strong = receiver()
if strong is None: self._disconnect(receiver_id, ANY_ID) continue
yield strong else: yield receiver
def disconnect(self, receiver: c.Callable[..., t.Any], sender: t.Any = ANY) -> None: """Disconnect ``receiver`` from being called when the signal is sent by ``sender``.
:param receiver: A connected receiver callable. :param sender: Disconnect from only this sender. By default, disconnect from all senders. """ sender_id: c.Hashable
if sender is ANY: sender_id = ANY_ID else: sender_id = make_id(sender)
receiver_id = make_id(receiver) self._disconnect(receiver_id, sender_id)
if ( "receiver_disconnected" in self.__dict__ and self.receiver_disconnected.receivers ): self.receiver_disconnected.send(self, receiver=receiver, sender=sender)
def _disconnect(self, receiver_id: c.Hashable, sender_id: c.Hashable) -> None: if sender_id == ANY_ID: if self._by_receiver.pop(receiver_id, None) is not None: for bucket in self._by_sender.values(): bucket.discard(receiver_id)
self.receivers.pop(receiver_id, None) else: self._by_sender[sender_id].discard(receiver_id) self._by_receiver[receiver_id].discard(sender_id)
def _make_cleanup_receiver( self, receiver_id: c.Hashable ) -> c.Callable[[weakref.ref[c.Callable[..., t.Any]]], None]: """Create a callback function to disconnect a weakly referenced receiver when it is garbage collected. """
def cleanup(ref: weakref.ref[c.Callable[..., t.Any]]) -> None: # If the interpreter is shutting down, disconnecting can result in a # weird ignored exception. Don't call it in that case. if not sys.is_finalizing(): self._disconnect(receiver_id, ANY_ID)
return cleanup
def _make_cleanup_sender( self, sender_id: c.Hashable ) -> c.Callable[[weakref.ref[t.Any]], None]: """Create a callback function to disconnect all receivers for a weakly referenced sender when it is garbage collected. """ assert sender_id != ANY_ID
def cleanup(ref: weakref.ref[t.Any]) -> None: self._weak_senders.pop(sender_id, None)
for receiver_id in self._by_sender.pop(sender_id, ()): self._by_receiver[receiver_id].discard(sender_id)
return cleanup
def _cleanup_bookkeeping(self) -> None: """Prune unused sender/receiver bookkeeping. Not threadsafe.
Connecting & disconnecting leaves behind a small amount of bookkeeping data. Typical workloads using Blinker, for example in most web apps, Flask, CLI scripts, etc., are not adversely affected by this bookkeeping.
With a long-running process performing dynamic signal routing with high volume, e.g. connecting to function closures, senders are all unique object instances. Doing all of this over and over may cause memory usage to grow due to extraneous bookkeeping. (An empty ``set`` for each stale sender/receiver pair.)
This method will prune that bookkeeping away, with the caveat that such pruning is not threadsafe. The risk is that cleanup of a fully disconnected receiver/sender pair occurs while another thread is connecting that same pair. If you are in the highly dynamic, unique receiver/sender situation that has lead you to this method, that failure mode is perhaps not a big deal for you. """ for mapping in (self._by_sender, self._by_receiver): for ident, bucket in list(mapping.items()): if not bucket: mapping.pop(ident, None)
def _clear_state(self) -> None: """Disconnect all receivers and senders. Useful for tests.""" self._weak_senders.clear() self.receivers.clear() self._by_sender.clear() self._by_receiver.clear()
class NamedSignal(Signal): """A named generic notification emitter. The name is not used by the signal itself, but matches the key in the :class:`Namespace` that it belongs to.
:param name: The name of the signal within the namespace. :param doc: The docstring for the signal. """
def __init__(self, name: str, doc: str | None = None) -> None: super().__init__(doc)
#: The name of this signal. self.name: str = name
def __repr__(self) -> str: base = super().__repr__() return f"{base[:-1]}; {self.name!r}>" # noqa: E702
class Namespace(dict[str, NamedSignal]): """A dict mapping names to signals."""
def signal(self, name: str, doc: str | None = None) -> NamedSignal: """Return the :class:`NamedSignal` for the given ``name``, creating it if required. Repeated calls with the same name return the same signal.
:param name: The name of the signal. :param doc: The docstring of the signal. """ if name not in self: self[name] = NamedSignal(name, doc)
return self[name]
class _PNamespaceSignal(t.Protocol): def __call__(self, name: str, doc: str | None = None) -> NamedSignal: ...
default_namespace: Namespace = Namespace()"""A default :class:`Namespace` for creating named signals. :func:`signal`creates a :class:`NamedSignal` in this namespace."""
signal: _PNamespaceSignal = default_namespace.signal"""Return a :class:`NamedSignal` in :data:`default_namespace` with the given``name``, creating it if required. Repeated calls with the same name return thesame signal."""1pip123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394Metadata-Version: 2.4Name: einopsVersion: 0.8.2Summary: A new flavour of deep learning operationsProject-URL: Homepage, https://github.com/arogozhnikov/einopsAuthor: Alex RogozhnikovLicense: MITLicense-File: LICENSEKeywords: deep learning,einops,machine learning,neural networks,scientific computations,tensor manipulationClassifier: Intended Audience :: Science/ResearchClassifier: License :: OSI Approved :: MIT LicenseClassifier: Programming Language :: Python :: 3Requires-Python: >=3.9Description-Content-Type: text/markdown
<!--<a href='http://arogozhnikov.github.io/images/einops/einops_video.mp4' ><div align="center"> <img src="http://arogozhnikov.github.io/images/einops/einops_video.gif" alt="einops package examples" /> <br> <small><a href='http://arogozhnikov.github.io/images/einops/einops_video.mp4'>This video in high quality (mp4)</a></small> <br><br></div></a>-->
<!-- this link magically rendered as video on github readme, unfortunately not in docs -->
https://user-images.githubusercontent.com/6318811/177030658-66f0eb5d-e136-44d8-99c9-86ae298ead5b.mp4
# einops [](https://github.com/arogozhnikov/einops/actions/workflows/run_tests.yml)[](https://badge.fury.io/py/einops)[](https://einops.rocks/)
Flexible and powerful tensor operations for readable and reliable code. <br />Supports numpy, pytorch, tensorflow, jax, and [others](#supported-frameworks).
## Recent updates:
- 0.8.0: tinygrad backend added, small fixes- 0.7.0: no-hassle `torch.compile`, support of [array api standard](https://data-apis.org/array-api/latest/API_specification/index.html) and more- 10'000🎉: github reports that more than 10k project use einops- einops 0.6.1: paddle backend added- einops 0.6 introduces [packing and unpacking](https://github.com/arogozhnikov/einops/blob/main/docs/4-pack-and-unpack.ipynb)- einops 0.5: einsum is now a part of einops- [Einops paper](https://openreview.net/pdf?id=oapKSVM2bcj) is accepted for oral presentation at ICLR 2022 (yes, it worth reading). Talk recordings are [available](https://iclr.cc/virtual/2022/oral/6603)
<details markdown="1"><summary>Previous updates</summary>- flax and oneflow backend added- torch.jit.script is supported for pytorch layers- powerful EinMix added to einops. [Einmix tutorial notebook](https://github.com/arogozhnikov/einops/blob/main/docs/3-einmix-layer.ipynb) </details>
<!--<div align="center"> <img src="http://arogozhnikov.github.io/images/einops/einops_logo_350x350.png" alt="einops package logo" width="250" height="250" /> <br><br></div> -->
## Tweets
> In case you need convincing arguments for setting aside time to learn about einsum and einops...[Tim Rocktäschel](https://twitter.com/_rockt/status/1230818967205425152)
> Writing better code with PyTorch and einops 👌[Andrej Karpathy](https://twitter.com/karpathy/status/1290826075916779520)
> Slowly but surely, einops is seeping in to every nook and cranny of my code. If you find yourself shuffling around bazillion dimensional tensors, this might change your life[Nasim Rahaman](https://twitter.com/nasim_rahaman/status/1216022614755463169)
[More testimonials](https://einops.rocks/pages/testimonials/)
## Contents
- [Installation](#Installation)- [Documentation](https://einops.rocks/)- [Tutorial](#Tutorials)- [API micro-reference](#API)- [Why use einops](#Why-use-einops-notation)- [Supported frameworks](#Supported-frameworks)- [Citing](#Citing)- [Repository](https://github.com/arogozhnikov/einops) and [discussions](https://github.com/arogozhnikov/einops/discussions)
## Installation <a name="Installation"></a>
Plain and simple:```bashpip install einops```
(`uv pip install einops` works as well)
## Tutorials <a name="Tutorials"></a>
Tutorials are the most convenient way to see `einops` in action
- part 1: [einops fundamentals](https://github.com/arogozhnikov/einops/blob/main/docs/1-einops-basics.ipynb)- part 2: [einops for deep learning](https://github.com/arogozhnikov/einops/blob/main/docs/2-einops-for-deep-learning.ipynb)- part 3: [packing and unpacking](https://github.com/arogozhnikov/einops/blob/main/docs/4-pack-and-unpack.ipynb)- part 4: [improve pytorch code with einops](http://einops.rocks/pytorch-examples.html)
Kapil Sachdeva recorded a small [intro to einops](https://www.youtube.com/watch?v=xGy75Pjsqzo).
## API <a name="API"></a>
`einops` has a minimalistic yet powerful API.
Three core operations provided ([einops tutorial](https://github.com/arogozhnikov/einops/blob/main/docs/)shows those cover stacking, reshape, transposition, squeeze/unsqueeze, repeat, tile, concatenate, view and numerous reductions)
```pythonfrom einops import rearrange, reduce, repeat# rearrange elements according to the patternoutput_tensor = rearrange(input_tensor, 't b c -> b c t')# combine rearrangement and reductionoutput_tensor = reduce(input_tensor, 'b c (h h2) (w w2) -> b h w c', 'mean', h2=2, w2=2)# copy along a new axisoutput_tensor = repeat(input_tensor, 'h w -> h w c', c=3)```
Later additions to the family are `pack` and `unpack` functions (better than stack/split/concatenate):
```pythonfrom einops import pack, unpack# pack and unpack allow reversibly 'packing' multiple tensors into one.# Packed tensors may be of different dimensionality:packed, ps = pack([class_token_bc, image_tokens_bhwc, text_tokens_btc], 'b * c')class_emb_bc, image_emb_bhwc, text_emb_btc = unpack(transformer(packed), ps, 'b * c')```
Finally, einops provides einsum with a support of multi-lettered names:
```pythonfrom einops import einsum, pack, unpack# einsum is like ... einsum, generic and flexible dot-product# but 1) axes can be multi-lettered 2) pattern goes last 3) works with multiple frameworksC = einsum(A, B, 'b t1 head c, b t2 head c -> b head t1 t2')```
### EinMix
`EinMix` is a generic linear layer, perfect for MLP Mixers and similar architectures.
### Layers
Einops provides layers (`einops` keeps a separate version for each framework) that reflect corresponding functions
```pythonfrom einops.layers.torch import Rearrange, Reducefrom einops.layers.tensorflow import Rearrange, Reducefrom einops.layers.flax import Rearrange, Reducefrom einops.layers.paddle import Rearrange, Reduce```
<details markdown="1"><summary>Example of using layers within a pytorch model</summary>Example given for pytorch, but code in other frameworks is almost identical
```python from torch.nn import Sequential, Conv2d, MaxPool2d, Linear, ReLUfrom einops.layers.torch import Rearrange
model = Sequential( ..., Conv2d(6, 16, kernel_size=5), MaxPool2d(kernel_size=2), # flattening without need to write forward Rearrange('b c h w -> b (c h w)'), Linear(16*5*5, 120), ReLU(), Linear(120, 10),)```
No more flatten needed!
Additionally, torch layers as those are script-able and compile-able.Operations [are torch.compile-able](https://github.com/arogozhnikov/einops/wiki/Using-torch.compile-with-einops), but not script-able due to limitations of torch.jit.script.</details>
## Naming <a name="Naming"></a>
`einops` stands for Einstein-Inspired Notation for operations (though "Einstein operations" is more attractive and easier to remember).
Notation was loosely inspired by Einstein summation (in particular by `numpy.einsum` operation).
## Why use `einops` notation?! <a name="Why-use-einops-notation"></a>
### Semantic information (being verbose in expectations)
```pythony = x.view(x.shape[0], -1)y = rearrange(x, 'b c h w -> b (c h w)')```While these two lines are doing the same job in *some* context,the second one provides information about the input and output.In other words, `einops` focuses on interface: *what is the input and output*, not *how* the output is computed.
The next operation looks similar:
```pythony = rearrange(x, 'time c h w -> time (c h w)')```but it gives the reader a hint:this is not an independent batch of images we are processing,but rather a sequence (video).
Semantic information makes the code easier to read and maintain.
### Convenient checks
Reconsider the same example:
```pythony = x.view(x.shape[0], -1) # x: (batch, 256, 19, 19)y = rearrange(x, 'b c h w -> b (c h w)')```The second line checks that the input has four dimensions,but you can also specify particular dimensions.That's opposed to just writing comments about shapes since comments don't prevent mistakes,not tested, and without code review tend to be outdated```pythony = x.view(x.shape[0], -1) # x: (batch, 256, 19, 19)y = rearrange(x, 'b c h w -> b (c h w)', c=256, h=19, w=19)```
### Result is strictly determined
Below we have at least two ways to define the depth-to-space operation```python# depth-to-spacerearrange(x, 'b c (h h2) (w w2) -> b (c h2 w2) h w', h2=2, w2=2)rearrange(x, 'b c (h h2) (w w2) -> b (h2 w2 c) h w', h2=2, w2=2)```There are at least four more ways to do it. Which one is used by the framework?
These details are ignored, since *usually* it makes no difference,but it can make a big difference (e.g. if you use grouped convolutions in the next stage),and you'd like to specify this in your code.
### Uniformity
```pythonreduce(x, 'b c (x dx) -> b c x', 'max', dx=2)reduce(x, 'b c (x dx) (y dy) -> b c x y', 'max', dx=2, dy=3)reduce(x, 'b c (x dx) (y dy) (z dz) -> b c x y z', 'max', dx=2, dy=3, dz=4)```These examples demonstrated that we don't use separate operations for 1d/2d/3d pooling,those are all defined in a uniform way.
Space-to-depth and depth-to space are defined in many frameworks but how about width-to-height? Here you go:
```pythonrearrange(x, 'b c h (w w2) -> b c (h w2) w', w2=2)```
### Framework independent behavior
Even simple functions are defined differently by different frameworks
```pythony = x.flatten() # or flatten(x)```
Suppose `x`'s shape was `(3, 4, 5)`, then `y` has shape ...
- numpy, pytorch, cupy, chainer, jax: `(60,)`- keras, tensorflow.layers, gluon: `(3, 20)`
`einops` works the same way in all frameworks.
### Independence of framework terminology
Example: `tile` vs `repeat` causes lots of confusion. To copy image along width:```pythonnp.tile(image, (1, 2)) # in numpyimage.repeat(1, 2) # pytorch's repeat ~ numpy's tile```
With einops you don't need to decipher which axis was repeated:```pythonrepeat(image, 'h w -> h (tile w)', tile=2) # in numpyrepeat(image, 'h w -> h (tile w)', tile=2) # in pytorchrepeat(image, 'h w -> h (tile w)', tile=2) # in tfrepeat(image, 'h w -> h (tile w)', tile=2) # in jaxrepeat(image, 'h w -> h (tile w)', tile=2) # in cupy... (etc.)```
[Testimonials](https://einops.rocks/pages/testimonials/) provide users' perspective on the same question.
## Supported frameworks <a name="Supported-frameworks"></a>
Einops works with ...
- [numpy](http://www.numpy.org/)- [pytorch](https://pytorch.org/)- [tensorflow](https://www.tensorflow.org/)- [jax](https://github.com/google/jax)- [cupy](https://github.com/cupy/cupy)- [flax](https://github.com/google/flax) (community)- [paddle](https://github.com/PaddlePaddle/Paddle) (community)- [oneflow](https://github.com/Oneflow-Inc/oneflow) (community)- [tinygrad](https://github.com/tinygrad/tinygrad) (community)- [pytensor](https://github.com/pymc-devs/pytensor) (community)
```pythonfrom einops import rearrange => from einops.array_api import rearrange```
But actually it is even better: einops can be used with *any* framework that supports[Python array API standard](https://data-apis.org/array-api/latest/API_specification/index.html),to name a few:
- numpy >= 2.0- [MLX](https://github.com/ml-explore/mlx) # yes, einops works with apple's framework- [pydata/sparse](https://github.com/pydata/sparse) >= 0.15 # and works with sparse tensors- [cubed](https://github.com/cubed-dev/cubed) # and with distributed tensors too- [quantco/ndonnx](https://github.com/Quantco/ndonnx)- jax- cupy- dask is supported via [array-api-compat](https://github.com/data-apis/array-api-compat)
## Development
Devcontainer is provided, this environment can be used locally, or on your server,or within github codespaces. To start with devcontainers in vs code, clone repo, and click 'Reopen in Devcontainer'.
Starting from einops 0.8.1, einops distributes tests as a part of package.
```bash# pip install einops pytestpython -m einops.tests.run_tests numpy pytorch jax --pip-install```
`numpy pytorch jax` is an _example_, any subset of testable frameworks can be provided.Every framework is tested against numpy, so it is a requirement for tests.
Specifying `--pip-install` will install requirements in current virtualenv,and should be omitted if dependencies are installed locally.
To build/test docs:
```bashhatch run docs:serve # Serving on http://localhost:8000/```
## Citing einops <a name="Citing"></a>
Please use the following bibtex record
```text@inproceedings{ rogozhnikov2022einops, title={Einops: Clear and Reliable Tensor Manipulations with Einstein-like Notation}, author={Alex Rogozhnikov}, booktitle={International Conference on Learning Representations}, year={2022}, url={https://openreview.net/forum?id=oapKSVM2bcj}}```
## Supported python versions
`einops` works with python 3.9 or later.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758einops-0.8.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
einops-0.8.2.dist-info/METADATA,sha256=C9ZdsENoikT0opYIwculIcky9_928ji72GlEHhUBJlM,13724
einops-0.8.2.dist-info/RECORD,,
einops-0.8.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
einops-0.8.2.dist-info/licenses/LICENSE,sha256=MNmENkKW9R_67K1LAe4SfpUlDFBokY1LZvyWIGcj5DQ,1073
einops/__init__.py,sha256=MwPcYWGHKsJE0Uxlhf7YMv_Sf6vu9W9Y98hy1mRM6zk,438
einops/__pycache__/__init__.cpython-312.pyc,,
einops/__pycache__/_backends.cpython-312.pyc,,
einops/__pycache__/_torch_specific.cpython-312.pyc,,
einops/__pycache__/array_api.cpython-312.pyc,,
einops/__pycache__/einops.cpython-312.pyc,,
einops/__pycache__/packing.cpython-312.pyc,,
einops/__pycache__/parsing.cpython-312.pyc,,
einops/_backends.py,sha256=v4snGd66fVWeK0M8e3lNJ9j7_qmd8RMRyJVUTQB5slc,22528
einops/_torch_specific.py,sha256=QXgLFLDIgDa_Iqtv5gcucEeD3LHALYHJhaXRKgC5f4A,4329
einops/array_api.py,sha256=7mQ-4yhlWtqmtvcTZyI-pmDOSDbk3qpSCExl4-Vm1-o,5236
einops/einops.py,sha256=vmx5IWde_ePuzrPDLZZVw_-0Qsare1k8YRRaKt5ZL-8,38079
einops/experimental/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
einops/experimental/__pycache__/__init__.cpython-312.pyc,,
einops/experimental/__pycache__/indexing.cpython-312.pyc,,
einops/experimental/indexing.py,sha256=yFFflW3-kV6_5PPJU7_jOJsJBCWCWlE4dGlu9gwSPXo,121
einops/layers/__init__.py,sha256=jijwEY07Yr3rBx8N5zwZ-5qfbl-KX2BcRDK8NJFDaWA,3705
einops/layers/__pycache__/__init__.cpython-312.pyc,,
einops/layers/__pycache__/_einmix.cpython-312.pyc,,
einops/layers/__pycache__/flax.cpython-312.pyc,,
einops/layers/__pycache__/keras.cpython-312.pyc,,
einops/layers/__pycache__/oneflow.cpython-312.pyc,,
einops/layers/__pycache__/paddle.cpython-312.pyc,,
einops/layers/__pycache__/tensorflow.cpython-312.pyc,,
einops/layers/__pycache__/torch.cpython-312.pyc,,
einops/layers/_einmix.py,sha256=MQr6rymfMw-nzFmhvaLCcee0o7Ai8a1lmluxndWDAjU,11075
einops/layers/flax.py,sha256=Hk7L31wR2BHL63950-0hy3ivw4rc8NkgGW9jn1AKs-8,2518
einops/layers/keras.py,sha256=jxD9ZgYLWsKMkCIwojbBNSrY6c1pfXYhE2AMZa0pNXA,217
einops/layers/oneflow.py,sha256=djcKEZRJrWvxTuSsO4jJVZojieKiDPdUpP4SOpg_zTM,1864
einops/layers/paddle.py,sha256=YCHffUB4ha7wG-xEOeR9XcTPl48Kr57k_nBEx-J6FVA,1907
einops/layers/tensorflow.py,sha256=MjGApMbkb_gwAdGya7uGfPZ7olyETsRzbwymfJHii9E,3322
einops/layers/torch.py,sha256=BV-PzjoijGU9RGea1HCFuIMx4yccicz767M0jJDIH6U,2405
einops/packing.py,sha256=EZeGLgMRD78hB-0e80ubXvWHukh0_O_wJCf0Hbbdylo,7660
einops/parsing.py,sha256=vNPYcAs54-KLX1RtbkypGpsSpujzVkj_dQkZlUinLYw,6805
einops/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
einops/tests/__init__.py,sha256=CpSdrOGBSspTwuG6cAsYMGAwkTq0VuIBrehM7K-SYwU,3531
einops/tests/__pycache__/__init__.cpython-312.pyc,,
einops/tests/__pycache__/run_tests.cpython-312.pyc,,
einops/tests/__pycache__/test_einsum.cpython-312.pyc,,
einops/tests/__pycache__/test_examples.cpython-312.pyc,,
einops/tests/__pycache__/test_layers.cpython-312.pyc,,
einops/tests/__pycache__/test_ops.cpython-312.pyc,,
einops/tests/__pycache__/test_other.cpython-312.pyc,,
einops/tests/__pycache__/test_packing.cpython-312.pyc,,
einops/tests/__pycache__/test_parsing.cpython-312.pyc,,
einops/tests/run_tests.py,sha256=efJ2apHPOw1BKNIv5qZSNjHpgjSv0rJ4v9hbPbE7yNE,3072
einops/tests/test_einsum.py,sha256=Nycwg4a-4_Vz7l5f7mj2KIQ7QVs8P2SQIy1rnDcMOG8,11022
einops/tests/test_examples.py,sha256=6VVkHgov6hpEyoUGbMzFvRfoWTdP1Wr8RPji7G4pPlw,11510
einops/tests/test_layers.py,sha256=m8RqmBojvVMgr_ET6mhcGpbfYPasg60jUYux7ZlXhSM,18667
einops/tests/test_ops.py,sha256=4nxEGJWrmEG6cctYHGYuVVdEs5nUN9ziH7ukQYar44M,26884
einops/tests/test_other.py,sha256=vkWSJr7sn-COewksivTPaLe-GAmzLt7IEZF9TMnt360,13521
einops/tests/test_packing.py,sha256=AIBNiy8RftTj8dLv1AdNijkTXfrjCOTSw43fuD6Pfjc,10408
einops/tests/test_parsing.py,sha256=-YAJeJlhDb3U6xYIDRrtm6p4MSNWogeH6l3-np1wUCA,43891234Wheel-Version: 1.0Generator: hatchling 1.27.0Root-Is-Purelib: trueTag: py3-none-any123456789101112131415161718192021MIT License
Copyright (c) 2018 Alex Rogozhnikov
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.123456789101112131415161718192021222324252627282930313233343536373839# Copyright (c) Facebook, Inc. and its affiliates.# All rights reserved.## This source code is licensed under the BSD-style license found in the# LICENSE file in the root directory of this source tree.import torchfrom torch._functorch.deprecated import ( combine_state_for_ensemble, functionalize, grad, grad_and_value, hessian, jacfwd, jacrev, jvp, make_functional, make_functional_with_buffers, vjp, vmap,)
# utilities. Maybe these should go in their own namespace in the future?from torch._functorch.make_functional import ( FunctionalModule, FunctionalModuleWithBuffers,)
# Was never documentedfrom torch._functorch.python_key import make_fx
# Top-level APIs. Please think carefully before adding something to the# top-level namespace:# - private helper functions should go into torch._functorch# - very experimental things should go into functorch.experimental# - compilation related things should go into functorch.compile
__version__ = torch.__version__12345678# This file has moved to under torch/_functorch. It is not public API.# If you are not a PyTorch developer and you are relying on the following# imports, please file an issue.from torch._functorch.aot_autograd import ( aot_autograd_decompositions, KNOWN_TYPES, PytreeThunk,)1234567# This file has moved to under torch/_functorch. It is not public API.# If you are not a PyTorch developer and you are relying on the following# imports, please file an issue.from torch._functorch.eager_transforms import ( _assert_wrapped_functional, _unwrap_functional_tensor,)1234# This file has moved to under torch/_functorch. It is not public API.# If you are not a PyTorch developer and you are relying on the following# imports, please file an issue.from torch._functorch.make_functional import _swap_state12345678910111213141516# This file has moved to under torch/_functorch. It is not public API.# If you are not a PyTorch developer and you are relying on the following# imports, please file an issue.from torch._functorch.vmap import ( _add_batch_dim, _broadcast_to_and_flatten, _create_batched_inputs, _get_name, _process_batched_inputs, _remove_batch_dim, _unwrap_batched, _validate_and_get_batch_size, Tensor, tree_flatten, tree_unflatten,)123456789101112131415161718192021222324252627282930from torch._functorch import configfrom torch._functorch.aot_autograd import ( aot_function, aot_module, aot_module_simplified, compiled_function, compiled_module, get_aot_compilation_context, get_aot_graph_name, get_graph_being_compiled, make_boxed_compiler, make_boxed_func,)from torch._functorch.compilers import ( debug_compile, default_decompositions, draw_graph_compile, memory_efficient_fusion, nnc_jit, nop, print_compile, ts_compile,)from torch._functorch.fx_minifier import minifierfrom torch._functorch.partitioners import ( default_partition, draw_graph, min_cut_rematerialization_partition,)from torch._functorch.python_key import pythonkey_decompose123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181import disimport inspectfrom typing import Sequence, Union
import functorch._Cimport torchfrom functorch._C import dim as _C
from .tree_map import tree_flatten, tree_mapfrom .wrap_type import wrap_type
_C._patch_tensor_class()dims, DimList, dimlists = _C.dims, _C.DimList, _C.dimlists
class DimensionMismatchError(Exception): pass
class DimensionBindError(Exception): pass
from . import op_properties
# use dict to avoid writing C++ bindings for setpointwise = dict.fromkeys(op_properties.pointwise, True)
use_c = Trueif not use_c: from . import reference
class _Tensor: # fast path around slow wrapping/unwrapping logic for simply queries used # by the implementation...
@property def dims(self): return tuple(d for d in self._levels if isinstance(d, Dim))
def dim(self): return self.ndim
if use_c: __torch_function__ = classmethod(_C.__torch_function__) expand = _C._instancemethod(_C.expand) else: __torch_function__ = reference.__torch_function__ expand = reference.expand
index = _C._instancemethod(_C.index)
def __repr__(self): tensor, levels, ndim = self._tensor, self._levels, self.ndim return f"{tensor}\nwith dims={tuple(l + ndim if isinstance(l, int) else l for l in levels)} sizes={tuple(tensor.size())}"
TensorLike = (_Tensor, torch.Tensor)
class Dim(_C.Dim, _Tensor): # note that _C.Dim comes before tensor because we want the Dim API for things like size to take precendence. # Tensor defines format, but we want to print Dims with special formatting __format__ = object.__format__
class Tensor(_Tensor, _C.Tensor): if not use_c: from_batched = staticmethod(_C.Tensor_from_batched) from_positional = staticmethod(_C.Tensor_from_positional) sum = _C._instancemethod(_C.Tensor_sum)
def cat(tensors, dim, new_dim): n = dims() return stack(tensors, n, dim).index([n, dim], new_dim)
if use_c: _wrap = _C._wrap
def _def(name, *args, **kwargs): orig = getattr(torch.Tensor, name) setattr(_Tensor, name, _C._instancemethod(_wrap(orig, *args, **kwargs)))
t__getitem__ = _C._instancemethod(_C.__getitem__) stack = _C.stack split = _C._instancemethod(_C.split)else: _wrap, _def = reference._wrap, reference._def t__getitem__ = reference.t__getitem__ stack = reference.stack split = reference.split
# note: there is no python referencet__setitem__ = _C._instancemethod(_C.__setitem__)# this is patched in the C API because otherwise torch.Tensor will# no longer be considered a sequence and things will break# torch.Tensor.__getitem__ = t__getitem__
_Tensor.__getitem__ = t__getitem__# torch.Tensor.__setitem__ = t__setitem___Tensor.__setitem__ = t__setitem__
torch.Tensor.split = split_Tensor.split = splittorch.Tensor.expand = _C._instancemethod(_C.expand)torch.Tensor.index = _C._instancemethod(_C.index)wrap_type(use_c, _Tensor, torch.Tensor, _Tensor.__torch_function__)del _Tensor.ndim
if use_c: _Tensor.order = _C._instancemethod(_C.order)else: _Tensor.order = reference.positional
_def("mean")_def("sum")_def("all")_def("amax")_def("amin")_def("aminmax")_def("any")_def("count_nonzero")_def("logsumexp")_def("nanmean")_def("nansum")_def("prod")_def("std", keepdim_offset=2)_def("var", keepdim_offset=2)_def("max", single_dim=True)_def("min", single_dim=True)_def("argmax", single_dim=True)_def("argmin", single_dim=True)_def("kthvalue", single_dim=True)_def("median", single_dim=True)_def("nanmedian", single_dim=True)_def("mode", single_dim=True)_def("sort", reduce=False)_def("argsort", reduce=False)_def("unbind", single_dim=True)_def("chunk", dim_offset=1, reduce=False)_def("cummax", single_dim=True, reduce=False)_def("cummin", single_dim=True, reduce=False)_def("cumprod", single_dim=True, reduce=False)_def("cumprod_", single_dim=True, reduce=False)_def("cumsum", single_dim=True, reduce=False)_def("cumsum_", single_dim=True, reduce=False)_def("logcumsumexp", single_dim=True, reduce=False)_def("renorm", dim_offset=1, single_dim=True, reduce=False)_def("softmax", single_dim=True, reduce=False)softmax = _wrap(torch.nn.functional.softmax, single_dim=True, reduce=False)
# stuff to handle in the future, because they require special# binding logic for dims# cross# diag_embed# diagonal# diagonal_scatter# diff# nanquantile# quantile# roll# rot90# topk (new dimes on output)# should these all be subsumed by inplace indexing?# index_add_# index_add# index_copy# index_copy_# index_fill# index_fill_# index_select# scatter# scatter_# scatter_add# scatter_add_# scatter_reducelib/python3.12/site-packages/_multiprocess/__init__.pyAdded+8
lib/python3.12/site-packages/_multiprocess/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/big_modeling.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/checkpointing.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/data_loader.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/hooks.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/inference.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/launchers.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/local_sgd.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/logging.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/memory_utils.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/optimizer.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/scheduler.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/state.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/__pycache__/tracking.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/test_utils/scripts/__pycache__/test_cli.cpython-312.pycAdded
lib/python3.12/site-packages/accelerate/test_utils/scripts/__pycache__/test_script.cpython-312.pycAdded
lib/python3.12/site-packages/blinker/__init__.pyAdded+17
lib/python3.12/site-packages/blinker/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/blinker/__pycache__/_utilities.cpython-312.pycAdded
lib/python3.12/site-packages/blinker/__pycache__/base.cpython-312.pycAdded
lib/python3.12/site-packages/blinker/_utilities.pyAdded+64
lib/python3.12/site-packages/blinker/base.pyAdded+512
lib/python3.12/site-packages/blinker/py.typedAdded
lib/python3.12/site-packages/einops-0.8.2.dist-info/INSTALLERAdded+1
lib/python3.12/site-packages/einops-0.8.2.dist-info/METADATAAdded+394
lib/python3.12/site-packages/einops-0.8.2.dist-info/RECORDAdded+58
lib/python3.12/site-packages/einops-0.8.2.dist-info/WHEELAdded+4
lib/python3.12/site-packages/einops-0.8.2.dist-info/licenses/LICENSEAdded+21
lib/python3.12/site-packages/functorch/__init__.pyAdded+39
lib/python3.12/site-packages/functorch/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/_src/__init__.pyAdded
lib/python3.12/site-packages/functorch/_src/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/_src/aot_autograd/__init__.pyAdded+8
lib/python3.12/site-packages/functorch/_src/aot_autograd/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/_src/eager_transforms/__init__.pyAdded+7
lib/python3.12/site-packages/functorch/_src/eager_transforms/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/_src/make_functional/__init__.pyAdded+4
lib/python3.12/site-packages/functorch/_src/make_functional/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/_src/vmap/__init__.pyAdded+16
lib/python3.12/site-packages/functorch/_src/vmap/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/compile/__init__.pyAdded+30
lib/python3.12/site-packages/functorch/compile/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/dim/__init__.pyAdded+181
lib/python3.12/site-packages/functorch/dim/__pycache__/__init__.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/dim/__pycache__/batch_tensor.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/dim/__pycache__/delayed_mul_tensor.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/dim/__pycache__/dim.cpython-312.pycAdded
lib/python3.12/site-packages/functorch/dim/__pycache__/magic_trace.cpython-312.pycAdded