Skip to content

Commit

Permalink
Merge branch 'main' into add-einops
Browse files Browse the repository at this point in the history
  • Loading branch information
eldarkurtic committed Jul 13, 2023
2 parents 3afd07e + 6d836ed commit 772acbf
Show file tree
Hide file tree
Showing 63 changed files with 2,719 additions and 317 deletions.
4 changes: 2 additions & 2 deletions .MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ rahul-tuli
KSGulin
dbogunowicz
# anmarques
kylesayrs
# eldarkurtic
corey-nm
# chibukach
# shubhra
# abhinavnmagic
# eiofinov
dsikka
Satrat
2 changes: 0 additions & 2 deletions .github/workflows/Integrations-post-merge-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ jobs:
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- name: "Upgrade protobuf version"
run: pip3 install --upgrade protobuf
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,torchvision,deepsparse,onnxruntime,transformers,yolov5]
- name: "🔬 Running integrations tests (cadence: commit}})"
Expand Down
34 changes: 23 additions & 11 deletions .github/workflows/build-and-publish-release-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ jobs:

steps:
- name: Set up Docker Buildx
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
id: buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug

- name: Login to Github Packages
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: actions/checkout@v3
with:
fetch-depth: 1
Expand All @@ -39,12 +39,24 @@ jobs:
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF_NAME#*/})"

- name: Current Version Name
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
echo ${{ steps.extract_tag.outputs.tag }}
- name: Build and push sparseml with all dependencies and default cuda 11.1.1
if: ${{ contains(github.ref, 'refs/heads/release/') }}
- name: Build and push sparseml latest using default cuda 11.1.1
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v2
with:
context: ./docker
build-args: |
DEPS=all
VERSION=${{ steps.extract_tag.outputs.tag }}
push: true
tags: |
ghcr.io/neuralmagic/sparseml:latest
- name: Build and push sparseml with all dependencies and default cuda 11.1.1
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v2
with:
context: ./docker
Expand All @@ -55,8 +67,8 @@ jobs:
tags: |
ghcr.io/neuralmagic/sparseml:${{ steps.extract_tag.outputs.tag }}
- name: Build and push sparseml with all dependencies and cuda 10.2
if: ${{ contains(github.ref, 'refs/heads/release/') }}
- name: Build and push sparseml with all dependencies and cuda 10.2
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v2
with:
context: ./docker
Expand All @@ -69,7 +81,7 @@ jobs:
ghcr.io/neuralmagic/sparseml:${{ steps.extract_tag.outputs.tag }}-cu102
- name: Build and push sparseml-base cu11.1.1
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v2
with:
context: ./docker
Expand All @@ -81,7 +93,7 @@ jobs:
ghcr.io/neuralmagic/sparseml-base:${{ steps.extract_tag.outputs.tag }}
- name: Build and push sparseml-base cu10.2
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: docker/build-push-action@v2
with:
context: ./docker
Expand All @@ -95,5 +107,5 @@ jobs:
- name: Image digest
if: ${{ contains(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 0 additions & 2 deletions .github/workflows/integrations-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- name: "Upgrade protobuf version"
run: pip3 install --upgrade protobuf
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,torchvision,deepsparse,onnxruntime,transformers,yolov5]
- name: "🔬 Running integrations tests (cadence: pre-commit}})"
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/test-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
deepsparse: ${{ steps.deepsparse-check.outputs.output }}
onnx: ${{ steps.onnx-check.outputs.output }}
pytorch: ${{ steps.pytorch-check.outputs.output }}
tensorflow_v1: ${{ steps.tensorflow_v1-check.outputs.output }}
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -54,12 +53,6 @@ jobs:
((git diff --name-only origin/main HEAD | grep -E "[src|tests]/sparseml/pytorch|setup.py|.github")
|| (echo $GITHUB_REF | grep -E "refs/heads/[release/|main]"))
&& echo "::set-output name=output::1" || echo "::set-output name=output::0"
- name: "Checking if sparseml.tensorflow_v1 was changed"
id: tensorflow_v1-check
run: >
((git diff --name-only origin/main HEAD | grep -E "[src|tests]/sparseml/tensorflow_v1|setup.py|.github")
|| (echo $GITHUB_REF | grep -E "refs/heads/[release/|main]"))
&& echo "::set-output name=output::1" || echo "::set-output name=output::0"
base-tests:
runs-on: ubuntu-22.04
env:
Expand All @@ -80,8 +73,6 @@ jobs:
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- name: "Upgrade protobuf version"
run: pip3 install --upgrade protobuf
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,onnxruntime]
- name: "🔬 Running base tests"
Expand All @@ -106,8 +97,6 @@ jobs:
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- name: "Upgrade protobuf version"
run: pip3 install --upgrade protobuf
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,deepsparse,onnxruntime]
- name: "🔬 Running deepsparse tests"
Expand Down Expand Up @@ -160,30 +149,6 @@ jobs:
run: pip3 install .[dev,torchvision,onnxruntime]
- name: "🔬 Running pytorch tests"
run: make test TARGETS=pytorch
tensorflow-v1-tests:
runs-on: ubuntu-22.04
env:
SPARSEZOO_TEST_MODE: "true"
needs: test-setup
if: ${{needs.test-setup.outputs.tensorflow_v1 == 1}}
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.7'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: "neuralmagic/sparsezoo"
path: "sparsezoo"
ref: ${{needs.test-setup.outputs.branch}}
- name: "⚙️ Install sparsezoo dependencies"
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
- name: "Clean sparsezoo directory"
run: rm -r sparsezoo/
- name: "⚙️ Install dependencies"
run: pip3 install .[dev,tf_v1,onnxruntime]
- name: "🔬 Running tensorflow_v1 tests"
run: make test TARGETS=tensorflow_v1
compat-pytorch-1_9-pytorch-tests:
runs-on: ubuntu-22.04
env:
Expand Down
5 changes: 4 additions & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

# Developing SparseML

SparseML is developed and tested using Python 3.7-3.10.
SparseML is developed and tested using Python 3.8-3.10.
To develop SparseML, you will also need the development dependencies and to follow the styling guidelines.

Here are some details to get started.
Expand All @@ -40,6 +40,9 @@ Those can be installed by adding the framework name to the install extras. Frame
python3 -m pip install -e "./[dev,torch]"
```

Note: Running all pytorch tests using `make test TARGETS=torch`, also requires `torchvision`
and `onnxruntime` install all these dependencies using `python3 -m pip install -e "./[dev, torch, torchvision, onnxruntime]"`

**Code Styling and Formatting checks**

```bash
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ SparseML enables you to create a sparse model trained on your dataset in two way

## Installation

This repository is tested on Python 3.7-3.10, and Linux/Debian systems.
This repository is tested on Python 3.8-3.10, and Linux/Debian systems.

It is recommended to install in a [virtual environment](https://docs.python.org/3/library/venv.html) to keep your system in order.
Currently supported ML Frameworks are the following: `torch>=1.1.0,<1.14`, `tensorflow>=1.8.0,<2.0.0`, `tensorflow.keras >= 2.2.0`.
Currently supported ML Frameworks are the following: `torch>=1.1.0,<=2.0`, `tensorflow>=1.8.0,<2.0.0`, `tensorflow.keras >= 2.2.0`.

Install with pip using:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

# Installation

This repository is tested on Python 3.7-3.10, and Linux/Debian systems.
This repository is tested on Python 3.8-3.10, and Linux/Debian systems.
It is recommended to install in a [virtual environment](https://docs.python.org/3/library/venv.html) to keep your system in order.
Currently supported ML Frameworks are the following: `torch>=1.1.0,<1.14`, `tensorflow>=1.8.0,<=2.0.0`, `tensorflow.keras >= 2.2.0`.

Expand Down
26 changes: 26 additions & 0 deletions integrations/clip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# CLIP Export Examples

The examples in `clip_onnx_export.py` provide the steps needed to export a CLIP model using sparseml's onnx exporting functionality. The models and pretrained weights are pulled in from [OpenClip](https://github.com/mlfoundations/open_clip/tree/main) and the command line tools provided allow exporting of a given model's Text and Visual branches. See the OpenClip repository for a full list of available models. For the CoCa models available in OpenClip, an additional text-decoder is also exported.

## Installation

The examples provided require torch nighly and `open_clip_torch==2.20.0` to be installed. To work within the `sparseml` environment, be sure to set the environment variable `MAX_TORCH` to your installed version when
installing torch nightly.

Example: `MAX_TORCH="2.1.0.dev20230613+cpu"`
61 changes: 61 additions & 0 deletions integrations/clip/clip_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import torch
import torch.nn as nn


class VisualModel(nn.Module):
def __init__(self, visual_model: torch.nn.Module, output_tokens: bool):

super().__init__()

self.visual_model = visual_model
self.visual_model.output_tokens = output_tokens

def forward(self, x):
return self.visual_model(x)


class TextModel(nn.Module):
def __init__(
self,
token_embedding: torch.nn.Embedding,
positional_embedding: torch.nn.parameter.Parameter,
transformer: torch.nn.Module,
ln_final: torch.nn.LayerNorm,
text_projection: torch.nn.parameter.Parameter,
attn_mask: torch.Tensor,
):

super().__init__()

self.token_embedding = token_embedding
self.positional_embedding = positional_embedding
self.transformer = transformer
self.ln_final = ln_final
self.text_projection = text_projection
self.attn_mask = attn_mask
self.cast_dtype = self.transformer.get_cast_dtype()

def forward(self, input_ids):
x = self.token_embedding(input_ids).to(self.cast_dtype)
x = x + self.positional_embedding.to(self.cast_dtype)
x = x.permute(1, 0, 2) # NLD -> LND
x = self.transformer(x, attn_mask=self.attn_mask)
x = x.permute(1, 0, 2) # LND -> NLD
x = self.ln_final(x) # [batch_size, n_ctx, transformer.width]
# take features from the eot embedding (eot_token = highest in each sequence)
x = x[torch.arange(x.shape[0]), input_ids.argmax(dim=-1)] @ self.text_projection
return x
Loading

0 comments on commit 772acbf

Please sign in to comment.