PyCharm Remote Development
Remote development mainly involves moving the development environment (including code editing, compilation, running, etc.) from the local machine to a remote server. This process involves several key components and concepts:
1. Remote Server
The remote server hosts the remote development environment. It can be a physical server or a virtual machine in the cloud. For example, on the GPUGEEK
platform, the remote server is the platform instance. The server must be configured with an environment capable of running code.
2. Network Connection
Remote development heavily depends on network connectivity, allowing the local computer and the remote server to communicate, including file transfer, command execution, and returning results.
3. Development Tools and IDE
Developers use IDEs (Pycharm, VS Code, or others) on their local computer. These IDEs usually provide the ability to connect to a remote server and execute tasks in the remote environment.
Use Cases for Remote Development on the GPUGEEK Platform:
- The local computer has no GPU or insufficient hardware to run the project.
- The local environment setup is too complex, and you don’t want to spend time debugging it.
- Uploading code to the GPU server after local debugging is troublesome. It’s easier to debug directly on the server and then run.
- A unified development environment avoids situations where code runs locally but throws errors once uploaded to the instance.
Remote development relies heavily on network stability. On the GPUGEEK
platform, the IDE connection route is: Local IDE - GPUGEEK network forwarding server - GPUGEEK instance
. In the following situations, the local IDE may disconnect from the instance server:
- Local computer goes to sleep, or WiFi disconnects.
- Local network fluctuations cause disconnection from the GPUGEEK forwarding server.
- GPUGEEK forwarding server overload disconnects traffic.
- Data center hosting the instance experiences overload, causing latency or disconnection.
Summary: Using IDE tools to connect to instances for remote development is only suitable for code debugging. For long-term training tasks lasting hours or days, please log in to the instance terminal via SSH and use tools like tmux, screen, or nohup to run training processes in the background, to prevent interruptions caused by network issues.
Using the PyCharm IDE to connect to GPUGEEK
platform instances for remote development:
- Ensure your PyCharm is the Professional Edition. The Community Edition does not support remote development.
- Dataset synchronization via PyCharm is slow; only sync code files to the server.
- This demo uses PyCharm version 2023.3 (Professional Edition), build #PY-233.11799.259, with the Chinese language pack installed.
- Demonstrated on
macOS
. The Windows version may differ slightly.
- Windows
- macOS
- Linux
1. Create a New Project
Create a new project in PyCharm. If you already have a project locally, skip this step. For this demo, we cloned the Yolov5
project from GitHub and used the local interpreter to print a test page.
2. Configure Remote Connection to Instance and Python Interpreter
1. On macOS, click PyCharm → Settings
2. Project → Python Interpreter → Add Interpreter → SSH
3. Go to GPUGEEK Console → Personal Space → Instance Management, find the corresponding instance, click Login
, and copy the Login Command
and Login Password
Example:
Login command: ssh -p 11111 root@xxxxxxxx.gpugeek.com
Login password: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Breakdown:
Instance SSH host: xxxxxxxx.gpugeek.com
Instance SSH port: 11111
Instance login username: root
Instance login password: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Paste the information into PyCharm:
- Fill the instance SSH host in box 1.
- Fill the instance SSH port in box 2.
- Fill the instance username in box 3.
Click button 4 to proceed.
4. Enter the instance login password, then click Next
5. PyCharm will test SSH login and Python environment. Once verified, click Next
6. Configure the Python interpreter on the remote server instance
- Select Conda environment (GPUGEEK images include Conda with frameworks, CUDA, Python pre-installed in
base
). - If PyCharm fails to detect Conda, enter
/usr/local/miniconda3/bin/conda
. - Click to load the environment, PyCharm will fetch Conda environments.
- Use existing environment; if
base
doesn’t meet requirements, create a new one (note: new env has no frameworks or Python, install manually). - Select existing environment.
- Choose the project directory to sync with the remote instance.
- Enable auto-upload of project files to server.
- Local project path (e.g.,
/opt/yolov5
) must not include datasets. Limit code files to < 50MB; larger size may cause sync timeout. - Remote project path (e.g.,
/gz-data/yolov5
) is where files are synced. - After selecting, click Confirm.
7. Click Create → Finish
PyCharm will auto-sync /opt/yolov5
to /gz-data/yolov5
on the instance.
8. Run code in local PyCharm, output will use the remote interpreter
9. Use PyCharm terminal to log in to the instance
- Click bottom-left terminal.
- Select the created SSH server.
3. Test Running the Project
Show test run of yolov5
Directly running python to train yolov5 will check whether the current environment meets requirements,
then pull datasets from github and images.cocodataset.org.
If the dataset download fails, training cannot start. You can use network acceleration to solve this: https://gpugeek.com/docs/product/quick_start/network_turbo
(base) root@492132307857413:/gz-data/yolov5# apt-get update -y
(base) root@492132307857413:/gz-data/yolov5# apt-get install libgl1-mesa-glx ca-certificates -y
(base) root@492132307857413:/gz-data/yolov5# pip install -r requirements.txt
(base) root@492132307857413:/gz-data/yolov5# python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5n.yaml --batch-size 128
train: weights=, cfg=yolov5n.yaml, data=coco.yaml, hyp=data/hyps/hyp.scratch-low.yaml, epochs=300, batch_size=128, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=, cache=None, image_weights=False, device=, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=runs/train, name=exp, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5
YOLOv5 🚀 2023-12-12 Python-3.10.10 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24260MiB)
hyperparameters: lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
Comet: run 'pip install comet_ml' to automatically track and visualize YOLOv5 🚀 runs in Comet
TensorBoard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/
Dataset not found ⚠️, missing paths ['/gz-data/datasets/coco/val2017.txt']
Downloading https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017labels.zip to /gz-data/datasets/coco2017labels.zip...
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████ █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 46.4M/46.4M [00:04<00:00, 11.9MB/s]
Unzipping /gz-data/datasets/coco2017labels.zip...
Downloading http://images.cocodataset.org/zips/test2017.zip to /gz-data/datasets/coco/images/test2017.zip...
Downloading http://images.cocodataset.org/zips/val2017.zip to /gz-data/datasets/coco/images/val2017.zip...
Downloading http://images.cocodataset.org/zips/train2017.zip to /gz-data/datasets/coco/images/train2017.zip...
Unzipping /gz-data/datasets/coco/images/val2017.zip...
Unzipping /gz-data/datasets/coco/images/test2017.zip...
Unzipping /gz-data/datasets/coco/images/train2017.zip...
Dataset download success ✅ (1428.5s), saved to /gz-data/datasets
Downloading https://ultralytics.com/assets/Arial.ttf to /root/.config/Ultralytics/Arial.ttf...
100%|███████████████████████ ████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 755k/755k [00:00<00:00, 1.18MB/s]
from n params module arguments
0 -1 1 1760 models.common.Conv [3, 16, 6, 2, 2]
1 -1 1 4672 models.common.Conv [16, 32, 3, 2]
2 -1 1 4800 models.common.C3 [32, 32, 1]
3 -1 1 18560 models.common.Conv [32, 64, 3, 2]
4 -1 2 29184 models.common.C3 [64, 64, 2]
5 -1 1 73984 models.common.Conv [64, 128, 3, 2]
6 -1 3 156928 models.common.C3 [128, 128, 3]
7 -1 1 295424 models.common.Conv [128, 256, 3, 2]
8 -1 1 296448 models.common.C3 [256, 256, 1]
9 -1 1 164608 models.common.SPPF [256, 256, 5]
10 -1 1 33024 models.common.Conv [256, 128, 1, 1]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 6] 1 0 models.common.Concat [1]
13 -1 1 90880 models.common.C3 [256, 128, 1, False]
14 -1 1 8320 models.common.Conv [128, 64, 1, 1]
15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
16 [-1, 4] 1 0 models.common.Concat [1]
17 -1 1 22912 models.common.C3 [128, 64, 1, False]
18 -1 1 36992 models.common.Conv [64, 64, 3, 2]
19 [-1, 14] 1 0 models.common.Concat [1]
20 -1 1 74496 models.common.C3 [128, 128, 1, False]
21 -1 1 147712 models.common.Conv [128, 128, 3, 2]
22 [-1, 10] 1 0 models.common.Concat [1]
23 -1 1 296448 models.common.C3 [256, 256, 1, False]
24 [17, 20, 23] 1 115005 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [64, 128, 256]]
YOLOv5n summary: 214 layers, 1872157 parameters, 1872157 gradients, 4.6 GFLOPs
AMP: checks passed ✅
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.001), 60 bias
train: Scanning /gz-data/datasets/coco/train2017... 117266 images, 1021 backgrounds, 0 corrupt: 100%|██████████| 118287/118287 [00:12<00:00, 9333.47it/s]
train: WARNING ⚠️ /gz-data/datasets/coco/images/train2017/000000099844.jpg: 2 duplicate labels removed
train: WARNING ⚠️ /gz-data/datasets/coco/images/train2017/000000201706.jpg: 1 duplicate labels removed
train: WARNING ⚠️ /gz-data/datasets/coco/images/train2017/000000214087.jpg: 1 duplicate labels removed
train: WARNING ⚠️ /gz-data/datasets/coco/images/train2017/000000522365.jpg: 1 duplicate labels removed
train: New cache created: /gz-data/datasets/coco/train2017.cache
val: Scanning /gz-data/datasets/coco/val2017... 4952 images, 48 backgrounds, 0 corrupt: 100%|██████████| 5000/5000 [00:01<00:00, 4461.27it/s]
val: New cache created: /gz-data/datasets/coco/val2017.cache
AutoAnchor: 4.45 anchors/target, 0.995 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅
Plotting labels to runs/train/exp5/labels.jpg...
Image sizes 640 train, 640 val
Using 8 dataloader workers
Logging results to runs/train/exp5
Starting training for 300 epochs...
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
0/299 14.9G 0.09918 0.08274 0.08872 1793 640: 55%|█████▌ | 513/925 [05:39<02:40, 2.57it/s]
0/299 14.9G 0.09399 0.08324 0.08538 166 640: 100%|██████████| 925/925 [10:16<00:00, 1.50it/s]
Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 20/20 [00:46<00:00, 2.31s/it]
all 5000 36335 0.00279 0.0515 0.00313 0.00101
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
1/299 23.1G 0.07863 0.08435 0.07822 1657 640: 62%|██████▏ | 570/925 [05:58<02:41, 2.20it/s]
4. Check GPU Usage
(base) root@492132307857413:~# nvidia-smi
Tue Dec 12 19:48:41 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.23.08 Driver Version: 545.23.08 CUDA Version: 12.3 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3090 On | 00000000:21:00.0 Off | N/A |
| 50% 50C P2 162W / 350W | 22807MiB / 24576MiB | 88% Default |
| | | N/A |
+---------------------------------------------------------------------------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
+---------------------------------------------------------------------------------------+