Skip to content

Fix issue #22 - conda-env-kernel-image example is broken #26

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 7 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

examples/conda-env-kernel-image/.idea/conda-env-kernel-image.iml
examples/conda-env-kernel-image/.idea/inspectionProfiles/profiles_settings.xml
examples/conda-env-kernel-image/.idea/modules.xml
examples/conda-env-kernel-image/.idea/vcs.xml
2 changes: 1 addition & 1 deletion examples/conda-env-kernel-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM continuumio/miniconda3:4.9.2

COPY environment.yml .
RUN conda env create -f environment.yml
RUN conda env update -f environment.yml --prune
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sry missed this earlier. Why do we need this change? what is prune trying to achieve?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original sample, this iwll create a new conda environment called myenv. Then, since base environment is being selected by default in Studio, so how do you switch to myenv conda?
With this change, I override the base environment, which is selected by default by Studio.

31 changes: 28 additions & 3 deletions examples/conda-env-kernel-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The Conda environment must have the appropriate kernel package installed, for e.

### Building the image

Build the Docker image and push to Amazon ECR.
Build the Docker image.
```
# Modify these as required. The Docker registry endpoint can be tuned based on your current region from https://docs.aws.amazon.com/general/latest/gr/ecr.html#ecr-docker-endpoints
REGION=<aws-region>
Expand All @@ -23,6 +23,31 @@ aws --region ${REGION} ecr create-repository --repository-name smstudio-custom
# Build and push the image
aws --region ${REGION} ecr get-login-password | docker login --username AWS --password-stdin ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom
docker build . -t ${IMAGE_NAME} -t ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}
```

### Local testing

Run the image locally to verify that the kernels in the image are visible to a Kernel Gateway.
```
docker run -it "$IMAGE_NAME" bash
```

Run the container with a KernelGateway to validate that the kernels are visible from the REST endpoint exposed to the host.

```
docker run -it -p 8888:8888 "$IMAGE_NAME" bash -c 'pip install jupyter_kernel_gateway && jupyter-kernelgateway --ip 0.0.0.0 --debug --port 8888'
```

Verify the Kernel Gateway is started successfully (e.g., *[KernelGatewayApp] Jupyter Kernel Gateway at http://0.0.0.0:8888* in the Docker logs) and validate that you can list the kernelspecs in the the running container

```
curl http://0.0.0.0:8888/api/kernelspecs
```


### Pushing the image
Push the Docker image to Amazon ECR
```
docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}
```

Expand Down Expand Up @@ -61,7 +86,7 @@ Create a Domain, providing the SageMaker Image and AppImageConfig in the Domain
aws --region ${REGION} sagemaker create-domain --cli-input-json file://create-domain-input.json
```

If you have an existing Domain, you can also use the `update-domain`
If you have an existing Domain, you can also use the `update-domain`. Replace the placeholder for Domain ID in `update-domain-input.json`

```bash
aws --region ${REGION} sagemaker update-domain --cli-input-json file://update-domain-input.json
Expand All @@ -82,7 +107,7 @@ docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAG
```


Create new App Image Version.
Create new App Image Version
```
aws --region ${REGION} sagemaker create-image-version \
--image-name ${IMAGE_NAME} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"KernelGatewayImageConfig": {
"KernelSpecs": [
{
"Name": "conda-env-myenv-py",
"Name": "python3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super confused, how did it ever work before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be python3 so this is a good question...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got similar working correctly this week (conda-env-mycoolenv-py) - I believe this is the auto-detection mentioned in "Kernel discovery" section of the custom image spec? I logged docs feedback that they should clarify there what the "Name"s are for auto-detected conda environments.

I believe this is something that SageMaker or jupyter_kernel_gateway is doing? Because as discussed here seems like auto-setup of conda envs as Jupyter kernels is not automatic from conda itself?

"DisplayName": "Python [conda env: myenv]"
}
],
Expand Down
4 changes: 2 additions & 2 deletions examples/conda-env-kernel-image/environment.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: myenv
name: base
channels:
- conda-forge
dependencies:
- python=3.8
- python=3.9
- numpy
- awscli
- boto3
Expand Down