Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary
Last synced: 8 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: towhee-io
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 729 KB
Statistics
  • Stars: 5
  • Watchers: 2
  • Forks: 4
  • Open Issues: 0
  • Releases: 1
Created almost 4 years ago · Last pushed over 3 years ago
Metadata Files
Readme Contributing License Code of conduct Citation

README.md

Towhee Compiler

Towhee compiler is a Python JIT compiler that speeds up AI-related codes by native code generation. The project is inspired by Numba, Pyjion and TorchDynamo. Towhee compiler uses a frame evaluation hook (see [PEP 523]: https://www.python.org/dev/peps/pep-0523/) to get the chance of compiling python bytecodes into native code.

The code is based on a forked version of torchdynamo, which extract fx.Graph by trace the execution of python code. But the goal of towhee compiler is whole program code generation, which also includes program that can not be represented by fx.Graph.

Install

Install with pip

Some environments are not yet supported (like m1 etc.), please try installing from source.

bash $ pip install towhee.compiler

Install from source code

bash $ git clone https://github.com/towhee-io/towhee-compiler.git $ cd towhee-compiler && pip install -r requirements $ python3 setup.py develop

Examples

Run with Torch Model

  • Compile

Towhee compiler can speedup any models, for example, we just need to add jit_compile context to the image_embedding function.

```python import torch import torchvision.models as models import numpy as np import towhee.compiler from towhee.compiler import jit_compile

towhee.compiler.config.debug = True

torchmodel = models.resnet50() torchmodel = torch.nn.Sequential(*(list(torchmodel.children())[:-1])) torchmodel = torch_model.eval()

def imageembedding(inputs): imgs = torch.tensor(inputs) embedding = torchmodel(imgs).detach().numpy() return embedding.reshape([2048])

inputs = np.random.randn(1, 3, 244, 244).astype(np.float32) with jitcompile(): embeddings = imageembedding(inputs) ```

  • Timer

We have compiled the model with the nebullvm backend (the default backend in towhee.compiler ), and we can define a Timer class to record the time spent.

```python import time

class Timer: def init(self, name): self._name = name

def __enter__(self):
    self._start = time.time()
    return self

def __exit__(self, *args):
    self._interval = time.time() - self._start
    print('%s: %.2fs'%(self._name, self._interval))

```

And we can see that the compiled function is more than 3 times faster.

```python with Timer('Image Embedding'): embeddings = image_embedding(inputs)

with Timer('Image Embedding with towhee compiler'), jitcompile(): embeddingsjit = image_embedding(inputs) ```

Image Embedding: 0.14s

Image Embedding with towhee compiler: 0.04s

Run with Towhee

Towhee supports setting JIT to use towhee.compiler to compile.

  • Set JIT

For example, we can add set_jit('towhee') in image embedding pipeline, then the following operator will be automatically compiled

```python import towhee

embeddingstowhee = ( towhee.dc(['https://raw.githubusercontent.com/towhee-io/towhee/main/towheelogo.png']) .imagedecode() .setjit('towhee') .imageembedding.timm(modelname='resnet50') ) ```

  • Timer

And we can make two towhee pipeline function to record the time cost.

```python towheefunc = (towhee.dummyinput() .imageembedding.timm(modelname='resnet50') .as_function() )

towheefuncjit = (towhee.dummyinput() .setjit('towhee') .imageembedding.timm(modelname='resnet50') .as_function() ) ```

```python data = towhee.ops.imagedecode()('https://raw.githubusercontent.com/towhee-io/towhee/main/towheelogo.png')

with Timer('Towhee function'): emb = towhee_func(data)

with Timer('Towhee function with Compiler'): embjit = towheefunc_jit(data) ```

Towhee function: 0.14s

Towhee function with Compiler: 0.08s

Tests in Towhee Hub

According to the README of Operator on Towhee Hub, we set jit to compile and speedup model , theresults are as follows:

5.5 means that the performance after jit is 5.5 times, and N means no speedup or compilation failure. And more test results will be updated continuously.

Field Task Operator Speedup(CPU/GPU)
Image Image Embedding image_embedding.timm 1.3/1.3
image_embedding.data2vec 1.2/1.7
image_embedding.swag 1.4/N
Face Embedding face_embedding.inceptionresnetv1 3.2/N
Face Landmark face_landmark_detection.mobilefacenet 2.1/2.1
NLP Text Embedding text_embedding.transformers 2.6/N
text_embedding.data2vec 1.8/N
text_embedding.realm 5.5/1.9
text_embedding.xlm_prophetnet 2.1/2.8
Audio Audio Classification audio_classification.panns 1.6/N
Audio Embedding audio_embedding.vggish 1.5/N
audio_embedding.data2vec 1.5/N
Multimodal Image Text image_text_embedding.blip 2.3/N
Video Text video_text_embedding.bridge_former(modality='text') 2.1/N
video_text_embedding.frozen_in_time(modality='text') 2.2/N

Owner

  • Name: Towhee
  • Login: towhee-io
  • Kind: organization

Open source platform for generating embedding vectors.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: Ansel
    given-names: Jason
title: "TorchDynamo"
date-released: 2022-01-01
url: https://github.com/pytorch/torchdynamo

GitHub Events

Total
Last Year

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 79
  • Total Committers: 4
  • Avg Commits per committer: 19.75
  • Development Distribution Score (DDS): 0.278
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
reiase r****e@g****m 57
shiyu22 s****n@z****m 20
Jason Ansel j****l@j****t 1
Kaiyuan Hu k****u@z****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 1
  • Total pull requests: 51
  • Average time to close issues: 29 days
  • Average time to close pull requests: about 4 hours
  • Total issue authors: 1
  • Total pull request authors: 3
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.06
  • Merged pull requests: 49
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • shiyu22 (1)
Pull Request Authors
  • reiase (32)
  • shiyu22 (18)
  • Chiiizzzy (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 1 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 1
pypi.org: towhee.compiler

A JIT compiler for accelerating AI programs written in python.

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1 Last month
Rankings
Dependent packages count: 6.6%
Forks count: 17.3%
Average: 23.2%
Stargazers count: 23.3%
Dependent repos count: 30.6%
Downloads: 38.1%
Maintainers (1)
Last synced: 8 months ago

Dependencies

requirements.txt pypi
  • nebullvm *
  • numpy *
  • recordclass *
  • tabulate *
  • torch *
  • typeguard *
test_requirements.txt pypi
  • black ==22.6.0 test
  • flake8 ==4.0.1 test
  • isort ==5.10.1 test
  • numpy * test
  • pytest * test
  • tabulate * test
  • torch * test