dgx-spark-playbooks/nvidia/txt2kg/assets/deploy/services/gpu-viz/README.md

235 lines
6.4 KiB
Markdown
Raw Normal View History

2025-10-10 18:45:20 +00:00
# GPU Graph Visualization Services
2025-10-06 17:05:41 +00:00
## 🚀 Overview
2025-10-10 18:45:20 +00:00
This directory contains optional GPU-accelerated graph visualization services that run separately from the main txt2kg application. These services provide advanced visualization capabilities for large-scale graphs.
2025-10-06 17:05:41 +00:00
2025-10-10 18:45:20 +00:00
**Note**: These services are **optional** and not included in the default docker-compose configurations. They must be run separately.
2025-10-06 17:05:41 +00:00
2025-10-10 18:45:20 +00:00
## 📦 Available Services
### 1. Unified GPU Service (`unified_gpu_service.py`)
2025-12-02 19:43:52 +00:00
Combines **PyGraphistry Cloud** and **Local GPU (cuGraph)** processing into a single FastAPI service.
2025-10-10 18:45:20 +00:00
**Processing Modes:**
2025-10-06 17:05:41 +00:00
| Mode | Description | Requirements |
|------|-------------|--------------|
2025-12-02 19:43:52 +00:00
| **PyGraphistry Cloud** | Interactive GPU embeds in browser | API credentials |
2025-10-06 17:05:41 +00:00
| **Local GPU (cuGraph)** | Full GPU processing on your hardware | NVIDIA GPU + cuGraph |
| **Local CPU** | NetworkX fallback processing | None |
2025-10-10 18:45:20 +00:00
### 2. Remote GPU Rendering Service (`remote_gpu_rendering_service.py`)
Provides GPU-accelerated graph layout and rendering with iframe-embeddable visualizations.
### 3. Local GPU Service (`local_gpu_viz_service.py`)
Local GPU processing service with WebSocket support for real-time updates.
## 🛠️ Setup
### Prerequisites
2025-12-02 19:43:52 +00:00
- NVIDIA GPU with CUDA support (for GPU modes)
2025-10-10 18:45:20 +00:00
- RAPIDS cuGraph (for local GPU processing)
2025-12-02 19:43:52 +00:00
- PyGraphistry account (for cloud mode)
2025-10-10 18:45:20 +00:00
### Installation
2025-10-06 17:05:41 +00:00
```bash
2025-10-10 18:45:20 +00:00
# Install dependencies
pip install -r deploy/services/gpu-viz/requirements.txt
# For remote WebGPU service
pip install -r deploy/services/gpu-viz/requirements-remote-webgpu.txt
2025-10-06 17:05:41 +00:00
```
2025-10-10 18:45:20 +00:00
### Running Services
2025-10-06 17:05:41 +00:00
2025-10-10 18:45:20 +00:00
#### Unified GPU Service
2025-10-06 17:05:41 +00:00
```bash
2025-10-10 18:45:20 +00:00
cd deploy/services/gpu-viz
2025-10-06 17:05:41 +00:00
python unified_gpu_service.py
```
2025-10-10 18:45:20 +00:00
Service runs on: http://localhost:8080
#### Remote GPU Rendering Service
2025-10-06 17:05:41 +00:00
```bash
2025-10-10 18:45:20 +00:00
cd deploy/services/gpu-viz
python remote_gpu_rendering_service.py
2025-10-06 17:05:41 +00:00
```
2025-10-10 18:45:20 +00:00
Service runs on: http://localhost:8082
#### Using Startup Script
2025-10-06 17:05:41 +00:00
```bash
2025-10-10 18:45:20 +00:00
cd deploy/services/gpu-viz
./start_remote_gpu_services.sh
2025-10-06 17:05:41 +00:00
```
## 📡 API Usage
### Process Graph with Mode Selection
```bash
curl -X POST http://localhost:8080/api/visualize \
-H "Content-Type: application/json" \
-d '{
"graph_data": {
"nodes": [{"id": "1", "name": "Node 1"}, {"id": "2", "name": "Node 2"}],
"links": [{"source": "1", "target": "2", "name": "edge_1_2"}]
},
"processing_mode": "local_gpu",
"layout_algorithm": "force_atlas2",
"clustering_algorithm": "leiden",
"compute_centrality": true
}'
```
### Check Available Capabilities
```bash
curl http://localhost:8080/api/capabilities
```
Response:
```json
{
"processing_modes": {
2025-12-02 19:43:52 +00:00
"pygraphistry_cloud": {"available": true, "description": "..."},
"local_gpu": {"available": true, "description": "..."},
"local_cpu": {"available": true, "description": "..."}
2025-10-06 17:05:41 +00:00
},
"has_rapids": true,
"gpu_available": true
}
```
## 🎯 Frontend Integration
2025-10-10 18:45:20 +00:00
The txt2kg frontend includes built-in components for GPU visualization:
2025-10-06 17:05:41 +00:00
2025-10-10 18:45:20 +00:00
- `UnifiedGPUViewer`: Connects to unified GPU service
2025-12-02 19:43:52 +00:00
- `PyGraphistryViewer`: Direct PyGraphistry cloud integration
2025-10-10 18:45:20 +00:00
- `ForceGraphWrapper`: Three.js WebGPU visualization (default)
2025-10-06 17:05:41 +00:00
2025-10-10 18:45:20 +00:00
### Using GPU Services in Frontend
2025-10-06 17:05:41 +00:00
2025-10-10 18:45:20 +00:00
The frontend has API routes that can connect to these services:
2025-12-02 19:43:52 +00:00
- `/api/pygraphistry/*`: PyGraphistry integration
2025-10-10 18:45:20 +00:00
- `/api/unified-gpu/*`: Unified GPU service integration
To use these services, ensure they are running separately and configure the frontend environment variables accordingly.
2025-10-06 17:05:41 +00:00
2025-12-02 19:43:52 +00:00
### Mode-Specific Processing
2025-10-06 17:05:41 +00:00
```javascript
2025-12-02 19:43:52 +00:00
// PyGraphistry Cloud mode
2025-10-06 17:05:41 +00:00
const response = await fetch('/api/unified-gpu/visualize', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
graph_data: { nodes, links },
2025-12-02 19:43:52 +00:00
processing_mode: 'pygraphistry_cloud',
layout_type: 'force',
clustering: true,
gpu_acceleration: true
2025-10-06 17:05:41 +00:00
})
})
2025-12-02 19:43:52 +00:00
// Local GPU mode
2025-10-06 17:05:41 +00:00
const response = await fetch('/api/unified-gpu/visualize', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
graph_data: { nodes, links },
2025-12-02 19:43:52 +00:00
processing_mode: 'local_gpu',
layout_algorithm: 'force_atlas2',
clustering_algorithm: 'leiden',
compute_centrality: true
2025-10-06 17:05:41 +00:00
})
})
```
## 🔧 Configuration Options
2025-12-02 19:43:52 +00:00
### PyGraphistry Cloud Mode
- `layout_type`: "force", "circular", "hierarchical"
- `gpu_acceleration`: true/false
- `clustering`: true/false
2025-10-06 17:05:41 +00:00
### Local GPU Mode
- `layout_algorithm`: "force_atlas2", "spectral", "fruchterman_reingold"
- `clustering_algorithm`: "leiden", "louvain", "spectral"
- `compute_centrality`: true/false
### Local CPU Mode
- Basic processing with NetworkX fallback
- No additional configuration needed
## 📊 Response Format
```json
{
"processed_nodes": [...],
"processed_edges": [...],
"processing_mode": "local_gpu",
2025-12-02 19:43:52 +00:00
"embed_url": "https://hub.graphistry.com/...", // Only for cloud mode
"layout_positions": {...}, // Only for local GPU mode
2025-10-06 17:05:41 +00:00
"clusters": {...},
"centrality": {...},
"stats": {
"node_count": 1000,
"edge_count": 5000,
"gpu_accelerated": true,
"layout_computed": true,
"clusters_computed": true
},
"timestamp": "2024-01-01T12:00:00Z"
}
```
2025-12-02 19:43:52 +00:00
## 🚀 Benefits of Unified Approach
2025-10-06 17:05:41 +00:00
### ✅ Advantages
- **Single service** - One port, one deployment
- **Mode switching** - Choose best processing per graph
- **Fallback handling** - Graceful degradation if GPU unavailable
- **Consistent API** - Same interface for all modes
2025-12-02 19:43:52 +00:00
- **Better testing** - Easy comparison between modes
2025-10-06 17:05:41 +00:00
### 🎯 Use Cases
2025-12-02 19:43:52 +00:00
- **PyGraphistry Cloud**: Sharing visualizations, demos, production embeds
- **Local GPU**: Private data, large-scale processing, custom algorithms
2025-10-06 17:05:41 +00:00
- **Local CPU**: Development, testing, small graphs
## 🐛 Troubleshooting
### GPU Not Detected
```bash
# Check GPU availability
nvidia-smi
# Check RAPIDS installation
python -c "import cudf, cugraph; print('RAPIDS OK')"
```
2025-12-02 19:43:52 +00:00
### PyGraphistry Credentials
```bash
# Verify credentials are set
echo $GRAPHISTRY_PERSONAL_KEY
echo $GRAPHISTRY_SECRET_KEY
# Test connection
python -c "import graphistry; graphistry.register(personal_key_id='$GRAPHISTRY_PERSONAL_KEY', personal_key_secret='$GRAPHISTRY_SECRET_KEY'); print('PyGraphistry OK')"
```
2025-10-06 17:05:41 +00:00
### Service Health
```bash
curl http://localhost:8080/api/health
```
## 📈 Performance Tips
2025-12-02 19:43:52 +00:00
1. **Large graphs (>100k nodes)**: Use `local_gpu` mode
2. **Sharing/demos**: Use `pygraphistry_cloud` mode
3. **Development**: Use `local_cpu` mode for speed
4. **Mixed workloads**: Switch modes dynamically based on graph size