Skip to content

Commit

Permalink
Merge branch 'dora-rs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonRust authored Nov 23, 2024
2 parents 337b66e + 37b0716 commit e9404e1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 26 deletions.
42 changes: 34 additions & 8 deletions .github/workflows/node-hub-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
find-jobs:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
name: Find Jobs
outputs:
folders: ${{ steps.jobs.outputs.folders }}
Expand All @@ -26,17 +26,19 @@ jobs:
path: ./node-hub

ci:
runs-on: ubuntu-latest
runs-on: ${{ matrix.platform }}
needs: [find-jobs]
defaults:
run:
working-directory: node-hub/${{ matrix.folder }}
strategy:
matrix:
platform: [ubuntu-22.04, macos-14]
folder: ${{ fromJson(needs.find-jobs.outputs.folders )}}
fail-fast: false
steps:
- name: Checkout repository
if: runner.os == 'Linux' || github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
uses: actions/checkout@v2
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
Expand All @@ -56,23 +58,28 @@ jobs:
swap-storage: true

- name: Set up Python
if: runner.os == 'Linux' || github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Set up Poetry
if: runner.os == 'Linux' || github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
pip install black pylint pytest
- name: Set up Rust
if: runner.os == 'Linux' || github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Run Linting and Tests
## Run Linting and testing only on Mac for release workflows.
if: runner.os == 'Linux' || github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
run: |
chmod +x ../../.github/workflows/node_hub_test.sh
../../.github/workflows/node_hub_test.sh
Expand All @@ -84,10 +91,11 @@ jobs:
working-directory: node-hub/${{ matrix.folder }}
strategy:
matrix:
platform: [ubuntu-22.04, macos-14]
folder: ${{ fromJson(needs.find-jobs.outputs.folders )}}
runs-on: ubuntu-latest
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/')

fail-fast: false
runs-on: ${{ matrix.platform }}
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/'))
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -138,8 +146,26 @@ jobs:
else
if [[ -f "Cargo.toml" && -f "pyproject.toml" ]]; then
echo "Publishing $dir using maturin..."
pip3 install "maturin[patchelf]"
maturin publish --skip-existing
if [[ "${{ runner.os }}" == "Linux" ]]; then
pip3 install "maturin[zig]"
## The CI/CD is sequential to limit the number of workers used.
# x86_64-unknown-linux-gnu
maturin publish --skip-existing --zig
# aarch64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-gnu
maturin publish --target aarch64-unknown-linux-gnu --zig --skip-existing
# armv7-unknown-linux-musleabihf
rustup target add armv7-unknown-linux-musleabihf
maturin publish --target armv7-unknown-linux-musleabihf --zig --skip-existing
else
pip3 install maturin
maturin publish --skip-existing
fi
else
if [ -f "pyproject.toml" ]; then
echo "Publishing $dir using Poetry..."
Expand All @@ -154,7 +180,7 @@ jobs:
echo "Package '$package_name' version '$version' already exists on crates.io. Skipping publish."
else
echo "Publishing package '$package_name' version '$version'..."
cargo publish
cargo publish
fi
fi
fi
Expand Down
38 changes: 29 additions & 9 deletions .github/workflows/node_hub_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,39 @@ base_dir=$(basename "$dir")
if [[ " ${ignored_folders[@]} " =~ " ${base_dir} " ]]; then
echo "Skipping $base_dir as we cannot test it on the CI..."
else
if [ -f "$dir/Cargo.toml" ]; then
if [[ -f "Cargo.toml" && -f "pyproject.toml" ]]; then
echo "Running build and tests for Rust project in $dir..."

cargo check
cargo clippy
cargo build
cargo test

pip3 install "maturin[zig]"
maturin build --zig

# aarch64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-gnu
maturin build --target aarch64-unknown-linux-gnu --zig

# armv7-unknown-linux-musleabihf
rustup target add armv7-unknown-linux-musleabihf
maturin build --target armv7-unknown-linux-musleabihf --zig
else
if [ -f "$dir/pyproject.toml" ]; then
echo "Running linting and tests for Python project in $dir..."
pip install .
poetry run black --check .
poetry run pylint --disable=C,R --ignored-modules=cv2 **/*.py
poetry run pytest
fi
fi
if [ -f "$dir/Cargo.toml" ]; then
echo "Running build and tests for Rust project in $dir..."
cargo check
cargo clippy
cargo build
cargo test
else
if [ -f "$dir/pyproject.toml" ]; then
echo "Running linting and tests for Python project in $dir..."
pip install .
poetry run black --check .
poetry run pylint --disable=C,R --ignored-modules=cv2 **/*.py
poetry run pytest
fi
fi
fi
fi
12 changes: 6 additions & 6 deletions .github/workflows/pip-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
target: aarch64
- runner: ubuntu-22.04
target: armv7
# - runner: ubuntu-20.04
# - runner: ubuntu-22.04
# target: s390x
# - runner: ubuntu-20.04
# - runner: ubuntu-22.04
# target: ppc64le
repository:
- path: apis/python/node
Expand Down Expand Up @@ -73,9 +73,9 @@ jobs:
strategy:
matrix:
platform:
- runner: ubuntu-20.04
- runner: ubuntu-22.04
target: x86_64
- runner: ubuntu-20.04
- runner: ubuntu-22.04
target: x86
- runner: ubuntu-22.04
target: aarch64
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
- runner: macos-12
target: aarch64
repository:
- path: apis/python/node
Expand Down Expand Up @@ -236,7 +236,7 @@ jobs:
release:
name: Release
runs-on: ubuntu-22.04
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/')
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release' && startsWith(github.ref, 'refs/tags/')
needs: [linux, musllinux, musleabi, windows, macos, sdist]
strategy:
matrix:
Expand Down
3 changes: 2 additions & 1 deletion node-hub/dora-internvl/dora_internvl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def load_image(image_array: np.array, input_size=448, max_num=12):
def main():
# Handle dynamic nodes, ask for the name of the node in the dataflow, and the same values as the ENV variables.
model_path = os.getenv("MODEL", "OpenGVLab/InternVL2-1B")
device = "cuda:0" if torch.cuda.is_available() else "cpu"

# If you want to load a model using multiple GPUs, please refer to the `Multiple GPUs` section.
model = (
Expand All @@ -112,7 +113,7 @@ def main():
trust_remote_code=True,
)
.eval()
.cuda()
.to(device)
)
tokenizer = AutoTokenizer.from_pretrained(
model_path, trust_remote_code=True, use_fast=False
Expand Down
5 changes: 4 additions & 1 deletion node-hub/dora-qwenvl/dora_qwenvl/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from dora import Node
import torch
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
import numpy as np
Expand Down Expand Up @@ -83,7 +84,9 @@ def generate(frames: dict, question):
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")

device = "cuda:0" if torch.cuda.is_available() else "cpu"
inputs = inputs.to(device)

# Inference: Generation of the output
generated_ids = model.generate(**inputs, max_new_tokens=128)
Expand Down
2 changes: 1 addition & 1 deletion node-hub/dora-qwenvl/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages = [{ include = "dora_qwenvl" }]
python = "^3.7"
dora-rs = "^0.3.6"
numpy = "< 2.0.0"
torch = "^2.4.0"
torch = "^2.2.0"
torchvision = "^0.19"
transformers = "^4.45"
qwen-vl-utils = "^0.0.2"
Expand Down

0 comments on commit e9404e1

Please sign in to comment.