File size: 7,556 Bytes
b65eda7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | # π SSH Server Deployment Guide
## Deploying Apertus-8B on Remote GPU Server with SSH Access
This guide shows how to deploy Apertus Swiss AI on a remote GPU server and access it locally via SSH tunneling.
---
## π― Prerequisites
- **Remote GPU Server** with CUDA support (A40, A100, RTX 4090, etc.)
- **SSH access** to the server
- **Hugging Face access** to `swiss-ai/Apertus-8B-Instruct-2509`
- **Local machine** for accessing the dashboard
---
## π¦ Server Setup
### 1. Connect to Your Server
```bash
ssh username@your-server-ip
# Or if using a specific key:
ssh -i your-key.pem username@your-server-ip
```
### 2. Clone Repository
```bash
git clone https://github.com/yourusername/apertus-transparency-guide.git
cd apertus-transparency-guide
```
### 3. Setup Environment
```bash
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install torch transformers accelerate
pip install -r requirements.txt
# Install package
pip install -e .
```
### 4. Authenticate with Hugging Face
```bash
# Login to Hugging Face (required for model access)
huggingface-cli login
# Enter your token when prompted
```
### 5. Verify GPU Setup
```bash
# Check GPU availability
nvidia-smi
python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}'); print(f'GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"None\"}')"
```
---
## π§ Running Applications
### Option 1: Basic Chat Interface
```bash
# Run basic chat directly on server
python examples/basic_chat.py
```
### Option 2: Streamlit Dashboard with Port Forwarding
#### Start Streamlit on Server
```bash
# On your remote server
streamlit run dashboards/streamlit_transparency.py --server.port 8501 --server.address 0.0.0.0
```
#### Setup SSH Port Forwarding (From Local Machine)
```bash
# From your local machine, create SSH tunnel
ssh -L 8501:localhost:8501 username@your-server-ip
# Or with specific key:
ssh -L 8501:localhost:8501 -i your-key.pem username@your-server-ip
```
#### Access Dashboard Locally
Open your local browser and go to:
```
http://localhost:8501
```
The Streamlit dashboard will now be accessible on your local machine!
### Option 3: vLLM API Server
#### Start vLLM Server
```bash
# On your remote server
python -m vllm.entrypoints.openai.api_server \
--model swiss-ai/Apertus-8B-Instruct-2509 \
--dtype bfloat16 \
--temperature 0.8 \
--top-p 0.9 \
--max-model-len 8192 \
--host 0.0.0.0 \
--port 8000
```
#### Setup Port Forwarding for API
```bash
# From local machine
ssh -L 8000:localhost:8000 username@your-server-ip
```
#### Test API Locally
```python
import openai
client = openai.OpenAI(base_url="http://localhost:8000/v1", api_key="token")
response = client.chat.completions.create(
model="swiss-ai/Apertus-8B-Instruct-2509",
messages=[{"role": "user", "content": "Hello from remote server!"}],
temperature=0.8
)
print(response.choices[0].message.content)
```
---
## π οΈ Advanced Configuration
### Multiple Port Forwarding
You can forward multiple services at once:
```bash
# Forward both Streamlit (8501) and vLLM API (8000)
ssh -L 8501:localhost:8501 -L 8000:localhost:8000 username@your-server-ip
```
### Background Process Management
#### Using Screen (Recommended)
```bash
# Start a screen session
screen -S apertus
# Run your application inside screen
streamlit run dashboards/streamlit_transparency.py --server.port 8501 --server.address 0.0.0.0
# Detach: Ctrl+A, then D
# Reattach: screen -r apertus
# List sessions: screen -ls
```
#### Using nohup
```bash
# Run in background with nohup
nohup streamlit run dashboards/streamlit_transparency.py --server.port 8501 --server.address 0.0.0.0 > streamlit.log 2>&1 &
# Check if running
ps aux | grep streamlit
# View logs
tail -f streamlit.log
```
#### Using systemd (Production)
Create service file:
```bash
sudo nano /etc/systemd/system/apertus-dashboard.service
```
```ini
[Unit]
Description=Apertus Transparency Dashboard
After=network.target
[Service]
Type=simple
User=your-username
WorkingDirectory=/path/to/apertus-transparency-guide
Environment=PATH=/path/to/apertus-transparency-guide/.venv/bin
ExecStart=/path/to/apertus-transparency-guide/.venv/bin/streamlit run dashboards/streamlit_transparency.py --server.port 8501 --server.address 0.0.0.0
Restart=always
[Install]
WantedBy=multi-user.target
```
```bash
# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable apertus-dashboard
sudo systemctl start apertus-dashboard
# Check status
sudo systemctl status apertus-dashboard
```
---
## π Security Considerations
### SSH Key Authentication
Always use SSH keys instead of passwords:
```bash
# Generate key pair (on local machine)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/apertus_server
# Copy public key to server
ssh-copy-id -i ~/.ssh/apertus_server.pub username@your-server-ip
# Connect with key
ssh -i ~/.ssh/apertus_server username@your-server-ip
```
### Firewall Configuration
```bash
# Only allow SSH and your specific ports
sudo ufw allow ssh
sudo ufw allow from your-local-ip to any port 8501
sudo ufw allow from your-local-ip to any port 8000
sudo ufw enable
```
### SSH Config
Create `~/.ssh/config` on your local machine:
```
Host apertus
HostName your-server-ip
User your-username
IdentityFile ~/.ssh/apertus_server
LocalForward 8501 localhost:8501
LocalForward 8000 localhost:8000
```
Then simply connect with:
```bash
ssh apertus
```
---
## π Performance Monitoring
### GPU Monitoring
```bash
# Real-time GPU usage
watch -n 1 nvidia-smi
# Or install nvtop for better interface
sudo apt install nvtop
nvtop
```
### System Monitoring
```bash
# System resources
htop
# Or install and use btop
sudo apt install btop
btop
```
### Application Monitoring
```bash
# Monitor Streamlit process
ps aux | grep streamlit
# Check logs
journalctl -u apertus-dashboard -f # for systemd service
tail -f streamlit.log # for nohup
```
---
## π§ Troubleshooting
### Common Issues
#### Model Loading Fails
```bash
# Check HuggingFace authentication
huggingface-cli whoami
# Clear cache and retry
rm -rf ~/.cache/huggingface/
huggingface-cli login
```
#### Out of GPU Memory
```bash
# Check GPU memory usage
nvidia-smi
# Consider using quantization
python examples/basic_chat.py --load-in-8bit
```
#### Port Already in Use
```bash
# Find what's using the port
sudo lsof -i :8501
# Kill process if needed
sudo kill -9 <PID>
```
#### SSH Connection Issues
```bash
# Test connection
ssh -v username@your-server-ip
# Check if port forwarding is working
netstat -tlnp | grep 8501
```
### Logs and Debugging
```bash
# Check system logs
sudo journalctl -xe
# Check SSH daemon logs
sudo journalctl -u ssh
# Debug Streamlit issues
streamlit run dashboards/streamlit_transparency.py --logger.level debug
```
---
## π Quick Commands Reference
```bash
# Connect with port forwarding
ssh -L 8501:localhost:8501 username@your-server-ip
# Start Streamlit dashboard
streamlit run dashboards/streamlit_transparency.py --server.port 8501 --server.address 0.0.0.0
# Start vLLM API server
python -m vllm.entrypoints.openai.api_server --model swiss-ai/Apertus-8B-Instruct-2509 --host 0.0.0.0 --port 8000
# Monitor GPU
nvidia-smi
# Check running processes
ps aux | grep -E "(streamlit|vllm)"
```
Mit dieser Anleitung kannst du Apertus auf deinem GPU-Server laufen lassen und lokal ΓΌber SSH-Port-Forwarding darauf zugreifen! π¨π |