You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-5Lines changed: 37 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ like nvidia-smi, or iteratively fix and re-execute your training script within s
15
15
PyCharm Professional Edition or Visual Studio Code.
16
16
3. Port forwarding to access diagnostic tools running inside SageMaker, e.g., Dask dashboard, TensorBoard or Spark Web UI.
17
17
18
-
Other scenarios include but not limited to connecting to a remote Jupyter Notebook in SageMaker Studio from your IDE, connect with your browser to a TensorBoard process running in the cloud, or start a VNC session to SageMaker Studio to run GUI apps.
18
+
Other scenarios include but not limited to connecting to a remote Jupyter Notebook in SageMaker Studio from your IDE, or start a VNC session to SageMaker Studio to run GUI apps.
19
19
20
20
Also see our [Frequently Asked Questions](FAQ.md), especially if you're using Windows on your local machine.
21
21
@@ -49,6 +49,7 @@ monitor resources, produce thread-dumps for stuck jobs, and interactively run yo
49
49
-[Connecting to SageMaker inference endpoints with SSM](#inference)
50
50
-[Connecting to SageMaker batch transform jobs](#batch-transform)
51
51
-[Connecting to SageMaker processing jobs](#processing)
52
+
-[Forwarding TCP ports over SSH tunnel](#port-forwarding) - to access remote apps like Dask or Streamlit
52
53
-[Remote debugging with PyCharm Debug Server over SSH](#pycharm-debug-server) - let SageMaker run your code that connects to PyCharm, to start line-by-line debugging with [PyDev.Debugger](https://pypi.org/project/pydevd-pycharm/), a.k.a. pydevd
53
54
-[Remote code execution with PyCharm / VSCode over SSH](#remote-interpreter) - let PyCharm run or debug your code line-by-line inside SageMaker container with SSH interpreter
54
55
-[Local IDE integration with SageMaker Studio over SSH for PyCharm / VSCode](#studio) - iterate fast on a single node at early stages of development without submitting SageMaker jobs
@@ -424,6 +425,31 @@ import sagemaker_ssh_helper
424
425
sagemaker_ssh_helper.setup_and_start_ssh()
425
426
```
426
427
428
+
## <aname="port-forwarding"></a>Forwarding TCP ports over SSH tunnel
429
+
430
+
Previous sections focused on connecting to non-interactive SageMaker containers with SSM.
431
+
432
+
Next sections rely on the Session Manager capability to create an SSH tunnel over SSM connection. SageMaker SSH Helper in turn runs SSH session over SSH tunnel and forwards the ports, including the SSH server port 22 itself.
433
+
434
+
The helper script behind this logic is `sm-local-start-ssh`:
435
+
436
+
```shell
437
+
sm-local-start-ssh "$INSTANCE_ID" \
438
+
-R localhost:12345:localhost:12345 \
439
+
-L localhost:8787:localhost:8787 \
440
+
-L localhost:11022:localhost:22
441
+
```
442
+
443
+
You can pass `-L` parameters for forwarding remote container port to local machine (e.g., `8787` for [Dask dashboard](https://docs.dask.org/en/stable/dashboard.html) or `8501` for [Streamlit apps](https://docs.streamlit.io/library/get-started)) or `-R` for forwarding local port to remote container. Read more about these options in the [SSH manual](https://man.openbsd.org/ssh).
444
+
445
+
This low-level script takes the managed instance ID as a parameter. The next sections describe how to use the higher-level APIs that take the SageMaker resource name as a parameter and resolve it into the instance ID automatically (a.k.a. `sm-local-ssh-*` scripts):
446
+
447
+
*`sm-local-ssh-training`
448
+
*`sm-local-ssh-processing`
449
+
*`sm-local-ssh-inference`
450
+
*`sm-local-ssh-transform`
451
+
*`sm-local-ssh-ide`
452
+
427
453
## <aname="pycharm-debug-server"></a>Remote debugging with PyCharm Debug Server over SSH
428
454
429
455
This procedure uses PyCharm's Professional feature: [Remote debugging with the Python remote debug server configuration](https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config)
@@ -540,16 +566,22 @@ The dummy script may look like this:
540
566
541
567
```python
542
568
import time
569
+
from datetime import timedelta
543
570
544
-
import sagemaker_ssh_helper
545
-
sagemaker_ssh_helper.setup_and_start_ssh()
571
+
from sagemaker_ssh_helper import setup_and_start_ssh, is_last_session_timeout
546
572
547
-
while True:
573
+
setup_and_start_ssh()
574
+
575
+
while not is_last_session_timeout(timedelta(minutes=30)):
548
576
time.sleep(10)
549
577
```
550
578
579
+
The method `is_last_session_timeout()` will help to prevent unused resources and the job will end if there's were no SSM or SSH sessions for the specified period of time.
580
+
581
+
Keep in mind that SSM sessions will [terminate automatically due to user inactivity](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-preferences-timeout.html), but SSH sessions will keep running until either a user terminates them or network timeout occurs (e.g., when local machine hibernates).
582
+
551
583
Make also sure that you're aware of [SageMaker Managed Warm Pools](https://docs.aws.amazon.com/sagemaker/latest/dg/train-warm-pools.html)
552
-
feature, which is also helpful insuch a scenario.
584
+
feature, which is also helpful in the scenario when you need to rerun your code multiple times.
553
585
554
586
*Pro Tip:* Note that you can debug your code line by line in this scenario, too! See [the tutorial in PyCharm documentation](https://www.jetbrains.com/help/pycharm/debugging-your-first-python-application.html#debug). Some users might prefer this option instead of using Debug Server as a simpler alternative.
0 commit comments