|
| 1 | +# NIXL Integration for HiCache |
| 2 | + |
| 3 | +This directory contains the **NIXL (NVIDIA Inference Xfer Library)** integration for **HiCache**, enabling high-performance storage across multiple backends. |
| 4 | + |
| 5 | +NIXL provides a unified API for accessing various storage plugins, including but not limited to: |
| 6 | + |
| 7 | +- **Deepseek's 3FS APIs** for high-throughput file operations |
| 8 | +- **GPU Direct Storage (GDS)** for direct data movement between storage and GPU memory, bypassing CPU memory copies |
| 9 | +- **Amazon S3-compatible object storage** for key-value access patterns |
| 10 | + |
| 11 | +Additional backend integrations are planned for future releases. |
| 12 | + |
| 13 | +## NIXL Resources |
| 14 | + |
| 15 | +- **Project Repository**: [NIXL on GitHub](https://github.com/ai-dynamo/nixl) |
| 16 | +- **Documentation**: [NIXL Documentation](https://github.com/ai-dynamo/nixl/tree/main/docs) |
| 17 | + |
| 18 | +## Overview |
| 19 | + |
| 20 | +The NIXL integration consists of two main files: |
| 21 | + |
| 22 | +- **`hicache_nixl.py`** - Main HiCache storage connector using NIXL |
| 23 | +- **`nixl_utils.py`** - Utility classes for backend selection, registration, and file management |
| 24 | + |
| 25 | +## Components |
| 26 | + |
| 27 | +### HiCacheNixl |
| 28 | +The main storage connector that provides: |
| 29 | +- Single and batch tensor set/get operations |
| 30 | +- Automatic backend selection (3FS > POSIX > GDS_MT > GDS > OBJ) |
| 31 | +- High-performance file-based (or) object based storage access using NIXL |
| 32 | + |
| 33 | +### NixlUtils |
| 34 | +Consolidated utility classes: |
| 35 | +- **NixlBackendSelection** - Handles backend selection and creation |
| 36 | +- **NixlRegistration** - Manages memory registration for tensors, files and objects |
| 37 | +- **NixlFileManager** - Handles file system operations and NIXL tuple creation |
| 38 | + |
| 39 | +## Running Unit Tests |
| 40 | + |
| 41 | +### Prerequisites |
| 42 | +- NIXL library installed and available (latest main required for supporting object query) |
| 43 | +- PyTorch installed |
| 44 | +- Python 3.8+ |
| 45 | + |
| 46 | +### Unit tests from Project root |
| 47 | +Navigate to the project root directory (`/path/to/sglang`) and run: |
| 48 | + |
| 49 | +#### Run all NIXL tests: |
| 50 | +```bash |
| 51 | +PYTHONPATH=. python -m pytest test/srt/test_hicache_nixl_storage.py -o asyncio_mode=strict |
| 52 | +``` |
| 53 | + |
| 54 | +#### Run with verbose output: |
| 55 | +```bash |
| 56 | +PYTHONPATH=. python -m pytest test/srt/test_hicache_nixl_storage.py -v -o asyncio_mode=strict |
| 57 | +``` |
| 58 | + |
| 59 | +Note: The `-v` flag provides more detailed output, showing each test case name and its result. |
| 60 | + |
| 61 | +#### Run a specific test: |
| 62 | +```bash |
| 63 | +PYTHONPATH=. python -m pytest test/srt/test_hicache_nixl_storage.py -v -k test_single_set_get -o asyncio_mode=strict |
| 64 | +``` |
| 65 | + |
| 66 | +### From Tests Directory |
| 67 | +Navigate to the tests directory and run: |
| 68 | + |
| 69 | +```bash |
| 70 | +cd test/srt |
| 71 | +PYTHONPATH=../.. python -m pytest test_hicache_nixl_storage.py -o asyncio_mode=strict |
| 72 | +``` |
| 73 | +Note: The `-o asyncio_mode=strict` flag is added to suppress warnings about asyncio configuration. This is not required for test functionality but provides cleaner output. |
| 74 | + |
| 75 | +## Test Coverage |
| 76 | + |
| 77 | +Tests for this integration, a test suite can be found at `test_hicache_nixl_storage.py` which covers: |
| 78 | + |
| 79 | +### HiCache Integration Tests (4 tests) |
| 80 | +- Single tensor set/get operations |
| 81 | +- Batch tensor set/get operations |
| 82 | +- Mixed single and batch operations |
| 83 | +- Data integrity for various tensor types |
| 84 | + |
| 85 | +### File Management Tests (5 tests) |
| 86 | +- Basic file operations |
| 87 | +- NIXL tuple creation |
| 88 | +- Error handling in file operations |
| 89 | + |
| 90 | +### Registration Tests (2 tests) |
| 91 | +- Tensor registration with memory type detection |
| 92 | +- File registration using NIXL tuples |
| 93 | + |
| 94 | +## Expected Output |
| 95 | + |
| 96 | +When tests run successfully, you should see: |
| 97 | +- NIXL agent initialization messages |
| 98 | +- Backend selection messages (e.g., "Backend POSIX was instantiated") |
| 99 | +- Test results with "ok" for passed tests |
| 100 | +- Summary showing "Ran X tests in Y seconds" and "OK" |
| 101 | + |
| 102 | +## Troubleshooting |
| 103 | + |
| 104 | +### Import Errors |
| 105 | +If you encounter `ModuleNotFoundError`, ensure: |
| 106 | +- You're running from the correct directory |
| 107 | +- `PYTHONPATH` is set correctly |
| 108 | +- NIXL library is properly installed |
| 109 | + |
| 110 | +### NIXL Errors |
| 111 | +If NIXL operations fail: |
| 112 | +- Check that NIXL is properly installed |
| 113 | +- Verify that required plugins are available |
| 114 | +- Ensure file permissions are correct for test directories |
| 115 | + |
| 116 | +## File Structure |
| 117 | + |
| 118 | +``` |
| 119 | +python/sglang/srt/mem_cache/nixl/ |
| 120 | +├── hicache_nixl.py # Main HiCache storage connector |
| 121 | +├── nixl_utils.py # All NIXL utility classes |
| 122 | +├── README.md # This file |
| 123 | +└── tests/ |
| 124 | + └── test_nixl_unified.py # All tests in one file |
| 125 | +``` |
| 126 | + |
| 127 | +## Dependencies |
| 128 | + |
| 129 | +- **NIXL**: NVIDIA Inference Xfer Library (version 0.4 or later) |
| 130 | + - Required plugins: POSIX (minimum), 3FS/GDS (optional for better performance) |
| 131 | + - See [NIXL Installation Guide](https://github.com/ai-dynamo/nixl/blob/main/README.md#installation) |
| 132 | +- **PyTorch**: For tensor operations (version 1.8 or later) |
| 133 | +- **Python 3.8+**: For type hints and modern features |
| 134 | + |
| 135 | +## Supported Features |
| 136 | + |
| 137 | +### Memory Types |
| 138 | +- **Tensor side**: multi-dimensional tensors of all numeric types (int32, int64, float32, float64) are supported. |
| 139 | + - Tensors can be on CPU or GPU (as long as a GPU capable backend such as GDS_MT is available). |
| 140 | + - Currently each tensor is mapped to a file or key, but it can be extended to support multiple keys per file or key. |
| 141 | + |
| 142 | +- **Storage side**: file and object are supported through their relevant backends (e.g., 3FS or OBJ). |
| 143 | + |
| 144 | +### Backend Priority |
| 145 | + |
| 146 | +The NIXL backend selection follows this priority order: |
| 147 | +1. **3FS** - Highest performance (if available) |
| 148 | + - Best for high-throughput file operations using Deepseek 3FS APIs |
| 149 | +2. **POSIX** - Standard file I/O (fallback) |
| 150 | + - Universal compatibility |
| 151 | + - Good for development and testing - Leverages both libaio/liburing |
| 152 | +3. **GDS_MT** - Multi-threaded GDS (if available) |
| 153 | + - Optimized for concurrent operations |
| 154 | + - Supports GPU Direct storage with multiple light weight threads |
| 155 | +4. **GDS** - GPU Direct Storage (if available) |
| 156 | + - Direct GPU-storage data path |
| 157 | + - Best for filesystems benefiting from batch operations and smaller IOs. |
| 158 | +5. **OBJ** - Amazon S3 based Object Storage |
| 159 | + - Key-value based storage |
| 160 | +The system automatically selects the best available backend, with POSIX as the default fallback. |
| 161 | + |
| 162 | +## Note |
| 163 | + |
| 164 | +This is v0 of the NIXL connector. Future versions will focus on further performance optimizations such as memory pre-registration (pre-allocating and registering memory buffers to reduce registration overhead during transfers) and block merging (combining related blocks as offsets within the same file to reduce file operations and improve throughput). These optimizations require changes at a higher layer, as the current HiCache API doesn't expose information like block relationships or hash patterns that would enable these optimizations. |
0 commit comments