Skip to content
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
09ab3e1
feat: add download acceleration infrastructure
deanq Aug 16, 2025
795c9e5
feat: integrate download acceleration with dependency installer
deanq Aug 16, 2025
046eb58
feat: add workspace acceleration support
deanq Aug 16, 2025
45a65fe
test: add download acceleration test coverage
deanq Aug 16, 2025
ce51390
chore: moved test-handler files to src/
deanq Aug 16, 2025
6c04de1
feat: runtime uses aria2 for accelerated parallel downloads
deanq Aug 16, 2025
66eb286
chore: update project structure and dependencies
deanq Aug 16, 2025
1930b4b
chore: updated tetra-rp
deanq Aug 19, 2025
731fd56
build: local-execution-test use make test-handler
deanq Aug 19, 2025
e829140
chore: update CLAUDE.md
deanq Aug 19, 2025
104b2da
chore: move these values to constants.py for maintainability
deanq Aug 19, 2025
f8aa89a
feat: add system package acceleration with nala
deanq Aug 19, 2025
cd56185
refactor: disable Python package download acceleration
deanq Aug 20, 2025
d7c996d
test: uv is no longer part of download accelerator
deanq Aug 20, 2025
2ab93e3
feat: implement accelerate_downloads parameter logic in RemoteExecutor
deanq Aug 21, 2025
b50a7bf
feat: add pip fallback for Python dependencies when acceleration disa…
deanq Aug 21, 2025
440d00d
feat: enhance HF model caching with hf_transfer/hf_xet strategy
deanq Aug 21, 2025
0320e4d
test: add comprehensive coverage for accelerate_downloads parameter
deanq Aug 21, 2025
034f770
test: update integration tests for new acceleration parameter
deanq Aug 21, 2025
9531079
chore: update dependencies and constants for download acceleration
deanq Aug 21, 2025
d75d320
refactor: remove pip installation method from dependency installer
deanq Aug 21, 2025
227b33e
test: update unit tests to expect UV instead of pip
deanq Aug 21, 2025
338a165
test: rename test file from pip to UV naming convention
deanq Aug 21, 2025
f88745d
feat: implement parallel execution for accelerated downloads
deanq Aug 21, 2025
f22e74d
feat: add async wrapper for HuggingFace model download acceleration
deanq Aug 21, 2025
816fc75
test: update tests for parallel execution and async dependencies
deanq Aug 21, 2025
c9ad0d3
test: comprehensive test coverage expansion and cleanup
deanq Aug 21, 2025
e31137a
refactor: optimize HF acceleration to use native Hub features
deanq Aug 21, 2025
e1db417
chore: memory correction
deanq Aug 21, 2025
76ab9c0
feat: implement HuggingFace download acceleration strategies
deanq Aug 21, 2025
c269bcd
feat: implement centralized log streaming system
deanq Aug 21, 2025
04e5b54
chore: these logs are for debug level
deanq Aug 21, 2025
f232a9c
Merge branch 'main' into deanq/ae-962-log-streaming
deanq Aug 29, 2025
83b3293
fix: merge conflicts
deanq Aug 29, 2025
f9a068c
chore: make update
deanq Aug 29, 2025
692d8fc
chore: these are debug lines
deanq Aug 29, 2025
ce2deae
chore: nala logs were too noisy
deanq Aug 29, 2025
90e3b9a
chore: updated tetra-rp
deanq Aug 29, 2025
e578007
fix: duplicated lines due to bad merge conflict resolution
deanq Aug 29, 2025
7e7201e
Merge branch 'main' into deanq/ae-962-log-streaming
deanq Sep 14, 2025
8091476
chore: update uv.lock
deanq Sep 14, 2025
8c8f902
fix: test-handler was not exactly testing properly
deanq Sep 15, 2025
47699d2
Merge branch 'deanq/ae-962-log-streaming' into deanq/ae-1165-bug-pyto…
deanq Sep 17, 2025
c6ac06d
chore: use GPU build for smoke tests
deanq Sep 17, 2025
cc92323
fix: multi-stage build loses crucial built-in system Python
deanq Sep 17, 2025
83787e7
chore: updated to latest submodule state
deanq Sep 17, 2025
b99af9d
fix: local/macos testing fails due to lack of apt-get or nala
deanq Sep 17, 2025
736c2eb
test: tests to confirm system Python access
deanq Sep 17, 2025
0785310
refactor: install_dependencies relies on uv and pip provisions
deanq Sep 17, 2025
16f7a1b
chore: better debug logs for dependency_installer
deanq Sep 17, 2025
ee6595e
feat: implement universal subprocess utility with automatic logging
deanq Sep 17, 2025
8c259c2
fix: use Docker detection for dependency installation method
deanq Sep 18, 2025
fcd51bd
docs: update CLAUDE.md with universal subprocess utility documentation
deanq Sep 18, 2025
b980e51
chore: vscode config to point to src
deanq Sep 18, 2025
0bda8a1
chore: no need for a NALA_CHECK_CMD constant
deanq Sep 18, 2025
177c3d2
build: update submodule
deanq Sep 18, 2025
d365f2a
chore: logs namespace is now just `tetra`
deanq Sep 18, 2025
8b2cf5f
Merge branch 'deanq/ae-962-log-streaming' into deanq/ae-1165-bug-pyto…
deanq Sep 18, 2025
b95451d
docs: System Python Runtime Architecture
deanq Sep 18, 2025
011890a
docs: Centralized Log Streaming System
deanq Sep 18, 2025
f11b4dc
chore: update and cleanup
deanq Sep 22, 2025
e2fe764
fix: docker uses system's conda python; local uses uv
deanq Sep 22, 2025
39a32de
fix: docker uses uv --system or conda python; local uses uv
deanq Sep 23, 2025
0447519
Merge branch 'deanq/ae-962-log-streaming' into deanq/ae-1165-bug-pyto…
deanq Sep 23, 2025
43888d5
Merge branch 'main' into deanq/ae-1165-bug-pytorchs-not-found
deanq Sep 23, 2025
564192a
build: fix CI to activate venv before `make test-handler`
deanq Sep 25, 2025
d26ef79
build: use Docker-based tests for CI
deanq Sep 25, 2025
3f1b07f
fix: conda path wasn't found on CPU image (applies only to Pytorch im…
deanq Sep 25, 2025
f4cbf30
Merge branch 'main' into deanq/ae-1165-bug-pytorchs-not-found
deanq Sep 25, 2025
f3d4a03
fix: completely remove local-execution-test-gpu
deanq Sep 25, 2025
3902147
build: use --rebase and not --merge
deanq Sep 25, 2025
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.envFile": "${workspaceFolder}/.env",
"python.analysis.extraPaths": [
"${workspaceFolder}/src"
]
}
246 changes: 128 additions & 118 deletions CLAUDE.md

Large diffs are not rendered by default.

29 changes: 9 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
FROM pytorch/pytorch:2.8.0-cuda12.8-cudnn9-runtime AS builder
FROM pytorch/pytorch:2.8.0-cuda12.8-cudnn9-runtime

WORKDIR /app

# Install build tools and uv (only in builder stage)
# Install system dependencies and uv
RUN apt-get update && apt-get install -y --no-install-recommends \
git curl build-essential ca-certificates \
curl ca-certificates nala \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& cp ~/.local/bin/uv /usr/local/bin/uv \
&& chmod +x /usr/local/bin/uv
&& chmod +x /usr/local/bin/uv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy app code and install dependencies
COPY README.md src/* pyproject.toml uv.lock ./
RUN uv sync


# --- Final stage: strip build tools, retain only runtime essentials ---
FROM pytorch/pytorch:2.8.0-cuda12.8-cudnn9-runtime

WORKDIR /app

# Install nala for system package acceleration in runtime stage
RUN apt-get update && apt-get install -y --no-install-recommends nala \
&& rm -rf /var/lib/apt/lists/*

# Copy app and uv binary from builder
COPY --from=builder /app /app
COPY --from=builder /usr/local/bin/uv /usr/local/bin/uv
RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \
&& uv pip install --system -r requirements.txt

CMD ["uv", "run", "handler.py"]
CMD ["python", "handler.py"]
Comment thread
pandyamarut marked this conversation as resolved.
31 changes: 9 additions & 22 deletions Dockerfile-cpu
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
# Stage 1: Build stage
FROM python:3.12-slim AS builder

WORKDIR /app

# Install minimal OS deps and uv
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates git build-essential \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& cp ~/.local/bin/uv /usr/local/bin/uv \
&& chmod +x /usr/local/bin/uv

# Copy app files and install deps
COPY README.md src/* pyproject.toml uv.lock ./
RUN uv sync

# Stage 2: Runtime stage
FROM python:3.12-slim

WORKDIR /app

# Install runtime dependencies
# Install system dependencies and uv
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates nala \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& cp ~/.local/bin/uv /usr/local/bin/uv \
&& chmod +x /usr/local/bin/uv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy only necessary files from the builder stage
COPY --from=builder /app /app
COPY --from=builder /usr/local/bin/uv /usr/local/bin/uv
# Copy app code and install dependencies
COPY README.md src/* pyproject.toml uv.lock ./
RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \
&& uv pip install --system -r requirements.txt

CMD ["uv", "run", "handler.py"]
CMD ["python", "handler.py"]
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGE = runpod/tetra-rp
TAG = local
TAG = $(or $(TETRA_IMAGE_TAG),local)
FULL_IMAGE = $(IMAGE):$(TAG)
FULL_IMAGE_CPU = $(IMAGE)-cpu:$(TAG)

Expand All @@ -20,16 +20,16 @@ help: # Show this help menu
dev: # Install development dependencies
uv sync --all-groups

update: # Upgrade all dependencies
uv sync --upgrade --all-groups
uv lock --upgrade

clean: # Remove build artifacts and cache files
rm -rf dist build *.egg-info
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pkl" -delete

upgrade: # Upgrade all dependencies
uv sync --upgrade
uv sync --all-groups

setup: dev # Initialize project, sync deps, update submodules
git submodule init
git submodule update --remote --merge
Expand Down Expand Up @@ -73,15 +73,15 @@ test-handler: # Test handler locally with all test_*.json files

# Smoke Tests (local on Mac OS)

smoketest-macos-build: setup # Build CPU-only Mac OS Docker image (macos/arm64)
smoketest-macos-build: setup # Build Mac OS Docker image (macos/arm64)
docker buildx build \
--platform linux/arm64 \
-f Dockerfile-cpu \
-t $(FULL_IMAGE_CPU)-mac \
-f Dockerfile \
-t $(FULL_IMAGE)-mac \
. --load

smoketest-macos: smoketest-macos-build # Test CPU Docker image locally
docker run --rm $(FULL_IMAGE_CPU)-mac ./test-handler.sh
smoketest-macos: smoketest-macos-build # Test Docker image locally
docker run --rm $(FULL_IMAGE)-mac ./test-handler.sh

# Linting commands
lint: # Check code with ruff
Expand Down
92 changes: 92 additions & 0 deletions docs/Centralized_Log_Streaming_System.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Centralized Log Streaming System

## Overview

This design implements a comprehensive log streaming architecture that captures all system logs during remote execution and includes them in the `FunctionResponse.stdout` for complete visibility into dependency installation, workspace setup, and function execution.

## Key Components

### 1. LogStreamer (`src/log_streamer.py`)
Thread-safe log capture system that buffers logs and streams them to the response output.

```mermaid
graph TB
A[Remote Function Execution] --> B[LogStreamer]
B --> C[Thread-Safe Buffer]
C --> D[Log Formatting]
D --> E[FunctionResponse.stdout]

F[Dependency Installation] --> B
G[Workspace Setup] --> B
H[System Operations] --> B
```

### 2. Centralized Logging (`src/logger.py`)
Unified logging configuration with:
- **Debug Format**: `timestamp | level | name | file:line | message`
- **Production Format**: `timestamp | level | message`
- **Namespace**: All logs use `tetra.*` hierarchy

### 3. Integration Points

```mermaid
sequenceDiagram
participant C as Client
participant RE as RemoteExecutor
participant LS as LogStreamer
participant DI as DependencyInstaller
participant WM as WorkspaceManager

C->>RE: Execute Function
RE->>LS: Start Log Streaming
RE->>DI: Install Dependencies
DI-->>LS: Log installation progress
RE->>WM: Setup Workspace
WM-->>LS: Log workspace operations
RE->>RE: Execute Function
RE-->>LS: Capture execution logs
LS->>RE: Streamed logs
RE->>C: FunctionResponse with logs in stdout
```

## Technical Changes

### Log Namespace Consolidation
- Changed from `worker_tetra` to `tetra` namespace
- Consistent logging hierarchy across all components
- Better alignment with tetra-rp logging standards

### Memory Management
- Configurable buffer size (default: 1000 entries)
- Automatic buffer rotation prevents memory issues
- Thread-safe operations with proper locking

### Error Resilience
- Log streaming failures don't break execution
- Graceful fallback when streaming unavailable
- Robust error handling in all log operations

## Files Modified

| Component | Purpose |
|-----------|---------|
| `src/log_streamer.py` | New centralized log streaming system |
| `src/logger.py` | New unified logging configuration |
| `src/remote_executor.py` | Integration with log streaming |
| `src/dependency_installer.py` | Log capture during installation |
| `src/test_log_streaming.json` | Test case for log visibility |

## Benefits

1. **Complete Observability**: All system operations visible in function response
2. **Debugging Efficiency**: Detailed logs help diagnose issues quickly
3. **Production Ready**: Clean, structured logs with appropriate formatting
4. **Thread Safety**: Concurrent operations don't interfere with log capture
5. **Memory Efficient**: Bounded buffer prevents memory exhaustion

## Testing

- New test case validates log capture and streaming
- Integration tests verify logs from dependency installation
- All existing tests pass with new logging system
- CI/CD maintains clean output with appropriate log levels
83 changes: 83 additions & 0 deletions docs/System_Python_Runtime_Architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# System Python Runtime Architecture

## Overview

This design addresses full use of PyTorch installation built into the base Docker image that we use for the runtime.

## Architecture Design

### System Python Runtime

```mermaid
graph TD
A[RunPod Request] --> B[src/handler.py]
B --> C[RemoteExecutor]
C --> D[Environment Detection]
D --> E{Docker?}
E -->|Yes| F[System UV Install]
E -->|No| G[Local UV Install]
F --> H[Function Execution]
G --> H

I[WorkspaceManager] --> C
J[DependencyInstaller] --> C
K[FunctionExecutor] --> C
```

## Key Points


### Dependency Installation Strategy

```mermaid
flowchart LR
A[Dependencies Required] --> B{Environment Check}
B -->|Docker| C[uv pip install --system]
B -->|Local| D[uv pip install]
C --> E[Direct System Installation]
D --> F[Managed Environment Installation]
```

### Component Architecture

```mermaid
graph TB
A[handler.py] --> B[RemoteExecutor]
B --> C[WorkspaceManager]
B --> D[DependencyInstaller]
B --> E[FunctionExecutor]
B --> F[ClassExecutor]

G[subprocess_utils] --> D
G --> E
G --> F

H[download_accelerator] --> D
I[serialization_utils] --> E
I --> F
```

## Benefits

### Improved Reliability
- **Environment detection** handles Docker vs local contexts
- **Centralized subprocess handling** through `run_logged_subprocess`
- **Consistent error handling** via `FunctionResponse` pattern

### Performance Optimizations
- **Faster cold starts** without venv initialization
- **Reduced container size** from simplified builds
- **Direct package access** eliminates the re-downloading torch and other built-in libraries

## Implementation Details

### System Installation Strategy
```python
# Docker environment
command = ["uv", "pip", "install", "--system", "--no-cache"] + packages

# Local environment
command = ["uv", "pip", "install", "--python-preference=managed"] + packages
```

This architecture refactor addresses the core PyTorch installation issues while maintaining API compatibility and improving operational simplicity.
4 changes: 2 additions & 2 deletions src/class_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _get_or_create_instance(self, request: FunctionRequest) -> Tuple[Any, str]:
return self.class_instances[instance_id], instance_id

# Create new instance
logging.info(f"Creating new instance of class: {request.class_name}")
logging.debug(f"Creating new instance of class: {request.class_name}")

# Execute class code
namespace: Dict[str, Any] = {}
Expand Down Expand Up @@ -154,7 +154,7 @@ def _get_or_create_instance(self, request: FunctionRequest) -> Tuple[Any, str]:
"last_used": datetime.now().isoformat(),
}

logging.info(f"Created instance with ID: {instance_id}")
logging.debug(f"Created instance with ID: {instance_id}")
return instance, instance_id

def _update_instance_metadata(self, instance_id: str):
Expand Down
7 changes: 0 additions & 7 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,3 @@
"wget",
]
"""List of system packages that benefit from nala's accelerated installation."""

NALA_CHECK_CMD = ["which", "nala"]
"""Command to check if nala is available."""

# Logging Configuration
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
"""Standard log format string used across the application."""
Loading