All Projects → Linux-cpp-lisp → opt_einsum_fx

Linux-cpp-lisp / opt_einsum_fx

Licence: MIT License
Einsum optimization using opt_einsum and PyTorch FX graph rewriting

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to opt einsum fx

PyOptSamples
Optimization sample codes on Python
Stars: ✭ 20 (+53.85%)
Mutual labels:  optimization
nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (+430.77%)
Mutual labels:  optimization
Unreal-Development-Guides-and-Tips
High-level concept explanations, detailed tutorials, performance considerations, shortcuts and other useful content that aims to improve your Unreal Engine 4 development journey.
Stars: ✭ 118 (+807.69%)
Mutual labels:  optimization
Coluna.jl
Branch-and-Price-and-Cut in Julia
Stars: ✭ 128 (+884.62%)
Mutual labels:  optimization
kafka-assignment-optimizer
Kafka Partitions Assignment Optimizer
Stars: ✭ 16 (+23.08%)
Mutual labels:  optimization
energy-py-linear
Optimize battery storage using mixed integer linear programming
Stars: ✭ 33 (+153.85%)
Mutual labels:  optimization
Fake-Interior-Shader-for-GodotEngine
Interior Mapping shader for the Godot Game Engine 3.x that works with both GLES3 and GLES2.
Stars: ✭ 40 (+207.69%)
Mutual labels:  optimization
pyPESTO
python Parameter EStimation TOolbox
Stars: ✭ 93 (+615.38%)
Mutual labels:  optimization
windows10-debloat
Collection of various scripts and apps to debloat Windows 10 for better privacy, performance and optimization.
Stars: ✭ 52 (+300%)
Mutual labels:  optimization
goga
Go evolutionary algorithm is a computer library for developing evolutionary and genetic algorithms to solve optimisation problems with (or not) many constraints and many objectives. Also, a goal is to handle mixed-type representations (reals and integers).
Stars: ✭ 39 (+200%)
Mutual labels:  optimization
pikaia
Modern Fortran Edition of the Pikaia Genetic Algorithm
Stars: ✭ 29 (+123.08%)
Mutual labels:  optimization
utf8
Fast UTF-8 validation with range algorithm (NEON+SSE4+AVX2)
Stars: ✭ 60 (+361.54%)
Mutual labels:  optimization
hmg
💝 My personal Gentoo/Linux configuration backup files
Stars: ✭ 16 (+23.08%)
Mutual labels:  optimization
Teg
A differentiable programming language with an integration primitive that soundly handles interactions among the derivative, integral, and discontinuities.
Stars: ✭ 25 (+92.31%)
Mutual labels:  optimization
siconos
Simulation framework for nonsmooth dynamical systems
Stars: ✭ 120 (+823.08%)
Mutual labels:  optimization
falcon
A WordPress cleanup and performance optimization plugin.
Stars: ✭ 17 (+30.77%)
Mutual labels:  optimization
photometric optimization
Photometric optimization code for creating the FLAME texture space and other applications
Stars: ✭ 271 (+1984.62%)
Mutual labels:  optimization
arch-packages
Arch Linux performance important packages
Stars: ✭ 27 (+107.69%)
Mutual labels:  optimization
pigosat
Go (golang) bindings for Picosat, the satisfiability solver
Stars: ✭ 15 (+15.38%)
Mutual labels:  optimization
macos
macOS load bootup and optimization
Stars: ✭ 29 (+123.08%)
Mutual labels:  optimization

opt_einsum_fx

Documentation Status

Optimizing einsums and functions involving them using opt_einsum and PyTorch FX compute graphs.

Issues, questions, PRs, and any thoughts about further optimizing these kinds of operations are welcome!

For more information please see the docs.

Installation

PyPI

The latest release can be installed from PyPI:

$ pip install opt_einsum_fx

Source

To get the latest code, run:

$ git clone https://github.com/Linux-cpp-lisp/opt_einsum_fx.git

and install it by running

$ cd opt_einsum_fx/
$ pip install .

You can run the tests with

$ pytest tests/

Minimal example

import torch
import torch.fx
import opt_einsum_fx

def einmatvecmul(a, b, vec):
    """Batched matrix-matrix-vector product using einsum"""
    return torch.einsum("zij,zjk,zk->zi", a, b, vec)

graph_mod = torch.fx.symbolic_trace(einmatvecmul)
print("Original code:\n", graph_mod.code)
graph_opt = opt_einsum_fx.optimize_einsums_full(
    model=graph_mod,
    example_inputs=(
        torch.randn(7, 4, 5),
        torch.randn(7, 5, 3),
        torch.randn(7, 3)
    )
)
print("Optimized code:\n", graph_opt.code)

outputs

Original code:
import torch
def forward(self, a, b, vec):
    einsum_1 = torch.functional.einsum('zij,zjk,zk->zi', a, b, vec);  a = b = vec = None
    return einsum_1

Optimized code:
import torch
def forward(self, a, b, vec):
    einsum_1 = torch.functional.einsum('cb,cab->ca', vec, b);  vec = b = None
    einsum_2 = torch.functional.einsum('cb,cab->ca', einsum_1, a);  einsum_1 = a = None
    return einsum_2

We can measure the performance improvement (this is on a CPU):

from torch.utils.benchmark import Timer

batch = 1000
a, b, vec = torch.randn(batch, 4, 5), torch.randn(batch, 5, 8), torch.randn(batch, 8)

g = {"f": graph_mod, "a": a, "b": b, "vec": vec}
t_orig = Timer("f(a, b, vec)", globals=g)
print(t_orig.timeit(10_000))

g["f"] = graph_opt
t_opt = Timer("f(a, b, vec)", globals=g)
print(t_opt.timeit(10_000))

gives ~2x improvement:

f(a, b, vec)
  276.58 us
  1 measurement, 10000 runs , 1 thread

f(a, b, vec)
  118.84 us
  1 measurement, 10000 runs , 1 thread

Depending on your function and dimensions you may see even larger improvements.

License

opt_einsum_fx is distributed under an MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].