Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b0ccfa6
Command line tool to submit any cellarium-ml single task
sjfleming Nov 15, 2024
015897c
Update readme
sjfleming Nov 15, 2024
10d802e
Small tweaks
sjfleming Nov 15, 2024
bf011eb
Tool to submit a pipeline specified in a YAML
sjfleming Nov 16, 2024
0eaec00
Fix misspelling
sjfleming Nov 18, 2024
f5a980f
Remove unnecessary bit
sjfleming Nov 20, 2024
62ba40b
Remove defunct input args and fix usage of pipeline args
sjfleming Nov 20, 2024
5312d59
More hints
sjfleming Nov 20, 2024
c9c12eb
Add psutil to automatic installs (for stats monitoring)
sjfleming Nov 22, 2024
36ec981
set num threads, tiny boost for cpu tasks
sjfleming Feb 21, 2025
e5af493
enable full data localization - working
sjfleming Aug 2, 2025
172ff57
large refactor to deduplicate and enable local runs
sjfleming Aug 2, 2025
67d2435
fixes to the new refactor, working local and vertexai
sjfleming Aug 2, 2025
b6cdbad
small import change
sjfleming Aug 2, 2025
52e5959
install git to enable use of pytorch docker image
sjfleming Aug 3, 2025
4fdef1b
default to 8 cpus
sjfleming Aug 3, 2025
b0ecf43
draft of adding google batch backend
sjfleming Aug 3, 2025
57e74e4
update requirements and how they get installed in vertex and batch
sjfleming Aug 4, 2025
293aae2
install gpu drivers in batch
sjfleming Aug 4, 2025
7131648
batch related updates
sjfleming Aug 4, 2025
1ea40ec
more batch updates trying to get gpus to work
sjfleming Aug 4, 2025
0439373
fix machine type specs
sjfleming Aug 4, 2025
71f143c
tweaks aimed at mounting bucket as volume in batch
sjfleming Aug 4, 2025
0b1d7de
more updates to batch
sjfleming Aug 4, 2025
e3d9335
download to /tmp on batch
sjfleming Aug 4, 2025
624e18b
Allow non-mounting of bucket in batch
sjfleming Aug 5, 2025
8e61afc
critical speed optimizations in batch (container shared mem)
sjfleming Aug 5, 2025
0368a67
actually save checkpoints
sjfleming Aug 5, 2025
a43df2d
batch updates
sjfleming Mar 28, 2026
1b4f769
batch code cleanup
sjfleming Mar 28, 2026
a359bc8
repo cleanup
sjfleming Mar 28, 2026
02035ea
linting
sjfleming Mar 28, 2026
9834d45
better logging
sjfleming Mar 28, 2026
4acccb3
auto-override yaml dataset with --extract-bucket
sjfleming Mar 28, 2026
aa9e27c
lint
sjfleming Mar 28, 2026
ed53c4c
updates for batch
sjfleming Mar 30, 2026
e59adc3
Batch bug fixes, now working onepass
sjfleming Mar 30, 2026
36226db
Fix zero padded shard names for extract-bucket
sjfleming Mar 31, 2026
4caa443
update default seurat_v3 hvg config
sjfleming Mar 31, 2026
41ac151
speed up pip install
sjfleming Mar 31, 2026
70aef5f
formatting
sjfleming Mar 31, 2026
ce4cd09
fix persistent disk mounting and use gsutil for download
sjfleming Mar 31, 2026
dd3f617
fix data download issue
sjfleming Mar 31, 2026
10233f1
dynamic large shm for containers
sjfleming Mar 31, 2026
009f47e
format
sjfleming Mar 31, 2026
de53892
auto sweep local output files to default_root_dir
sjfleming Mar 31, 2026
a573051
remove bucket fuse mount, use sidecar rsync for outputs to get realti…
sjfleming Mar 31, 2026
067809d
fix test-examples
sjfleming Mar 31, 2026
62f1dd3
include scripts and configs in package
sjfleming Mar 31, 2026
8ddb437
update readme
sjfleming Mar 31, 2026
2f0826b
handle ckpt_path appropriately in batch
sjfleming Apr 2, 2026
cc870a8
fix handling of yaml path modifications
sjfleming Apr 2, 2026
a1fcbd7
some default configs
sjfleming Apr 3, 2026
5cd0972
modify sidecar file delocalization
sjfleming Apr 5, 2026
299d3a2
default config updates
sjfleming Apr 5, 2026
c83b78a
Include .csv.gz in delocalization and add logging
sjfleming Apr 5, 2026
21368d9
tidy logging
sjfleming Apr 5, 2026
a18eb3a
default n1-standard-16
sjfleming Apr 6, 2026
754e7e1
linting
sjfleming Apr 6, 2026
425dcf6
updates
sjfleming Apr 10, 2026
b3b917a
update
sjfleming Apr 11, 2026
60e88bd
update
sjfleming Apr 11, 2026
3e65166
ignore nextflow stuff
sjfleming May 13, 2026
fc54fb5
update scvi config for validation
sjfleming May 18, 2026
62bf235
add dependencies for scvi validation
sjfleming May 18, 2026
ef2656c
scvi tweaks
sjfleming May 18, 2026
33e7447
improve i/o by increasing file read-ahead
sjfleming May 22, 2026
97cbfd5
tweaks
sjfleming May 22, 2026
8948baa
io read-ahead command not working
sjfleming Jun 5, 2026
74ef491
latest
sjfleming Jun 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Lint check
run: make lint

test-examples:
needs: [lint]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# To re-enable live GCP submission, restore the auth step above and add a
# GCP_SA_KEY repo secret with batch.jobs.create + batch.jobs.get permissions.
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Test examples
run: make test-examples
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
my_configs/

# nextflow
.nextflow*
.nextflow/
local_outputs/
work/
nextflow*.html

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.PHONY: install lint format FORCE

install: FORCE
pip install -e .[dev]

lint: FORCE
ruff check .
ruff format --check .

format: FORCE
ruff check --fix .
ruff format .

test-examples: FORCE
cellarium-workflow submit-batch-component \
--tool onepass_mean_var_std \
--subcommand fit \
--config cellarium/workflows/example/onepass_train_config.yaml \
--project dsp-cellarium \
--location us-central1 \
--machine-type n1-standard-4 \
--accelerator-type nvidia-tesla-t4 \
--accelerator-count 1 \
--dry-run

FORCE:
232 changes: 219 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,227 @@
# Cellarium Workflows Example
This code contains helper functions and example to run scripts in Vertex AI platform (powered by Kubeflow)
# Cellarium Workflows

A CLI tool for submitting [cellarium-ml](https://github.com/cellarium-ai/cellarium-ml) training and inference jobs to different compute backends.

Example: start an scVI run on the entire 20250811 CZI cellxgene census on specified Google Compute Engine hardware, all from your command line:

## Quick start
* [Install gcloud CLI](https://cloud.google.com/sdk/docs/install)
* [Authenticate gcloud CLI util](https://cloud.google.com/docs/authentication/gcloud)
* Install project requirements like:
```bash
$ pip isntall -r requirements/base.txt
cellarium-workflow submit-batch-component \
--tool scvi \
--subcommand fit \
--config folder/scvi_config.yaml \
--machine-type n1-standard-16 \
--accelerator-type nvidia-tesla-t4 \
--accelerator-count 1 \
--extract-bucket gs://bucket/path/to/extract_files
```

## Example
Go to example dir
In this example, `gs://bucket/path/to/extract_files` is the bucket created by extracting data using `Cellarium Nexus`. If data or configs or output directories in the config file are in Google Cloud Storage, file localization will be handled automatically.

## Installation

```bash
$ cd cellarium/workflows/example
pip install -e .
```
Submit an example pipeline:

This installs the `cellarium-workflow` command.

## Backends

The best tested method is `submit-batch-component`, and we recommend it for most use cases.

| Sub-command | Where it runs |
|---|---|
| `local-single-component` | Local machine |
| `submit-vertex-component` | Vertex AI Pipelines (single step) |
| `submit-vertex-pipeline` | Vertex AI Pipelines (sequential multi-step) |
| `submit-batch-component` | Google Cloud Batch (single job) |
| `submit-batch-pipeline` | Google Cloud Batch (sequential multi-step) |

## Usage

### Local

Run a job on your local machine — useful for development and smoke-testing.

```bash
cellarium-workflow local-single-component \
--tool onepass_mean_var_std \
--subcommand fit \
--config /path/to/config.yaml
```

### Vertex AI — Single Component

Submit a single job to Vertex AI Pipelines.

```bash
$ python submit_example_pipeline.py --project_id dsp-cell-annotation-service --location us-central1 --display_name test --component_1_config gs://test-bucket/test-config-1.yaml --component_2_config gs://test-bucket/test-config-2.yaml
```
cellarium-workflow submit-vertex-component \
--tool onepass_mean_var_std \
--subcommand fit \
--config gs://bucket/config.yaml \
--project my-project \
--machine-type n1-standard-8 \
--accelerator-type NVIDIA_TESLA_T4 \
--accelerator-count 1
```

### Vertex AI — Pipeline

Submit a multi-step sequential pipeline to Vertex AI.

```bash
cellarium-workflow submit-vertex-pipeline \
--pipeline-config pipeline_config.yaml \
--project my-project
```

### Google Cloud Batch — Single Component

Submit a single job to Cloud Batch. Supports local SSD data staging, custom networking, and optional log capture to GCS.

```bash
cellarium-workflow submit-batch-component \
--tool scvi \
--subcommand fit \
--config gs://bucket/config.yaml \
--project my-project \
--machine-type n1-standard-4 \
--accelerator-type nvidia-tesla-t4 \
--accelerator-count 1
```

### Google Cloud Batch — Pipeline

Submit a multi-step pipeline as individual Cloud Batch jobs. Use `--submit-sequentially` to run them one at a time.

```bash
cellarium-workflow submit-batch-pipeline \
--config pipeline_config.yaml \
--project my-project \
--submit-sequentially true
```

## Configuration

### Training Config

A standard [PyTorch Lightning CLI](https://lightning.ai/docs/pytorch/stable/cli/lightning_cli.html) YAML. The key fields used by this tool are:

```yaml
trainer:
default_root_dir: gs://my-bucket/outputs/
data:
dadc:
class_path: cellarium.ml.data.DistributedAnnDataCollection
init_args:
filenames: gs://bucket/path/extract_{0..9446}.h5ad
shard_size: 10000
last_shard_size: 3147
```

The `filenames` field uses brace-expansion to reference sharded `.h5ad` files. You can pass `--extract-bucket gs://bucket/path/` to have the tool auto-populate `filenames`, `shard_size`, and `last_shard_size` from GCS at submission time instead of hardcoding them.

### Pipeline Config

A YAML file listing the steps to run in order:

```yaml
my_pipeline_name:
- tool: onepass_mean_var_std
subcommand: fit
config: gs://bucket/configs/onepass_config.yaml
machine_type: n1-standard-4
accelerator_type: nvidia-tesla-t4
accelerator_count: 1

- tool: scvi
subcommand: fit
config: gs://bucket/configs/scvi_config.yaml
machine_type: n1-standard-16
accelerator_type: nvidia-tesla-v100
accelerator_count: 1
max_run_duration: 7200s
```

Each step can specify its own machine type and GPU configuration. Fields not set on a step inherit the pipeline defaults.

## Authentication

```bash
gcloud auth application-default login
```

## Google Batch setup

For a new Google project which has never used Batch before, you will need to set up a few things. We have distilled this into a helper script, included here. Fill in `PROJECT_ID` with the appropriate value for your Google project.

```bash
#!/bin/bash

# =======================================================================
# Set your Google Cloud Project ID here
# =======================================================================
PROJECT_ID="your-project-id-here"

echo "Starting Google Batch setup for project: $PROJECT_ID..."

# 1. Enable the Google Batch API (and Compute Engine API, which is a prerequisite)
echo "Enabling necessary APIs..."
gcloud services enable batch.googleapis.com compute.googleapis.com \
--project="$PROJECT_ID"

# 2. Create a "default" VPC network
# (An auto-mode network automatically creates subnets in all regions, including us-central1)
echo "Creating 'default' VPC network..."
gcloud compute networks create default \
--subnet-mode=auto \
--project="$PROJECT_ID" || true

# 3. Turn on Private Google Access for the us-central1 subnet
echo "Enabling Private Google Access for us-central1..."
gcloud compute networks subnets update default \
--region=us-central1 \
--enable-private-ip-google-access \
--project="$PROJECT_ID"

# 4. Create an egress firewall rule for the Batch Agent
# This ensures the VM can reach out to Google APIs on port 443 even if standard egress is blocked
echo "Creating egress firewall rule for TCP 443..."
gcloud compute firewall-rules create allow-batch-agent-egress \
--network=default \
--direction=EGRESS \
--action=ALLOW \
--destination-ranges=0.0.0.0/0 \
--rules=tcp:443 \
--description="Allows Google Batch agent to communicate with Google APIs" \
--project="$PROJECT_ID" || true

# 5. Find the Compute Engine default service account
echo "Locating the Compute Engine default service account..."
PROJECT_NUMBER=$(gcloud projects describe "$PROJECT_ID" --format="value(projectNumber)")
COMPUTE_SA="${PROJECT_NUMBER}-compute@developer.gserviceaccount.com"
echo "Found Service Account: $COMPUTE_SA"

# 6. Grant the required IAM permissions to the service account
echo "Applying IAM roles..."

# Batch Agent Reporter (Critical for the VM to report status)
gcloud projects add-iam-policy-binding "$PROJECT_ID" \
--member="serviceAccount:$COMPUTE_SA" \
--role="roles/batch.agentReporter" \
--condition=None > /dev/null

# Logs Writer (Critical for stdout/stderr logs from the container)
gcloud projects add-iam-policy-binding "$PROJECT_ID" \
--member="serviceAccount:$COMPUTE_SA" \
--role="roles/logging.logWriter" \
--condition=None > /dev/null

# Storage Object Admin (Critical for mounting GCS buckets)
gcloud projects add-iam-policy-binding "$PROJECT_ID" \
--member="serviceAccount:$COMPUTE_SA" \
--role="roles/storage.objectAdmin" \
--condition=None > /dev/null

echo "Setup complete! The project $PROJECT_ID is ready for Google Batch."
```
Loading
Loading