Notebook Kernel Spec
This guide will walk you through using the Notebook Admin client to create and manage Kernel types that will be available to users in the Notebook Lab.
Creating Kernel Images
First, you need to create a kernel image. This is a Docker image that contains the software and configuration for the Kernel.
KernelImages can exist only in workspace workspaces/global
(global workspace).
The apply method in the example will delete all existing kernel images in the global workspace and replace them with the provided list.
See KernelImage documentation for more details.
import h2o_notebook
from h2o_notebook.clients.kernel_image.kernel_image_config import KernelImageConfig
from h2o_notebook.clients.kernel_image.type import KernelImageType
clients = h2o_notebook.login()
kernel_images = [
KernelImageConfig(
kernel_image_id="python",
kernel_image_type=KernelImageType.TYPE_PYTHON,
image="gcr.io/vorvan/h2oai/h2o-kernel-py:0.4.0",
display_name="Python",
disabled=False,
),
KernelImageConfig(
kernel_image_id="r",
kernel_image_type=KernelImageType.TYPE_R,
image="gcr.io/vorvan/h2oai/h2o-kernel-r:0.4.0",
display_name="R",
disabled=False,
),
KernelImageConfig(
kernel_image_id="python-spark",
kernel_image_type=KernelImageType.TYPE_SPARK_PYTHON,
image="gcr.io/vorvan/h2oai/h2o-kernel-pyspark:0.4.0",
display_name="Spark - Python",
disabled=False,
),
KernelImageConfig(
kernel_image_id="r-spark",
kernel_image_type=KernelImageType.TYPE_SPARK_R,
image="gcr.io/vorvan/h2oai/h2o-kernel-sparkr:0.4.0",
display_name="Spark - R",
disabled=False,
)
]
# This method may fail due to conflicts when existing KernelImage is referenced by a NotebookKernelSpec.
# Better run `clients.notebook_kernel_spec_client.apply_kernel_images_templates_notebook_specs()` method.
clients.kernel_image_client.apply_kernel_images(kernel_images)
Creating Kernel Templates
Next, you need to create a template which describes the resources and environmental settings for the kernel.
KernelTemplates can exist only in workspace workspaces/global
(global workspace) or workspaces/default
(users default workspace).
The apply method in the example will delete all existing kernel templates and replace them with the provided list.
See KernelTemplate documentation for more details.
import h2o_notebook
from h2o_notebook.clients.kernel_template.kernel_template_config import KernelTemplateConfig
clients = h2o_notebook.login()
kernel_templates = [
KernelTemplateConfig(
kernel_template_id="small",
gpu=0,
memory_bytes_limit="12Gi",
memory_bytes_request="12Gi",
max_idle_duration="1h",
),
KernelTemplateConfig(
kernel_template_id="medium",
gpu=0,
memory_bytes_limit="32Gi",
memory_bytes_request="32Gi",
max_idle_duration="1h",
),
KernelTemplateConfig(
kernel_template_id="large",
gpu=0,
memory_bytes_limit="128Gi",
memory_bytes_request="128Gi",
max_idle_duration="1h",
),
]
# This method may fail due to conflicts when existing KernelTemplate is referenced by a NotebookKernelSpec.
# Better run later `clients.notebook_kernel_spec_client.apply_kernel_images_templates_notebook_specs()` method .
clients.kernel_template_client.apply_global_kernel_templates(kernel_templates)
Creating Notebook Kernel Specs
Finally, you need to create a kernel spec which combines the kernel image and kernel template.
NotebookKernelSpec can exist only in workspace workspaces/global
(global workspace).
The apply method in the example will delete all existing notebook kernel specs and replace them with the provided list.
See NotebookKernelSpec documentation for more details.
import h2o_notebook
from h2o_notebook.clients.notebook_kernel_spec.notebook_kernel_spec_config import NotebookKernelSpecConfig
clients = h2o_notebook.login()
notebook_kernel_specs = [
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python",
kernel_image="workspaces/global/kernelImages/python",
kernel_template="workspaces/global/kernelTemplates/medium",
display_name="Python",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python-l",
display_name="Python [L]",
kernel_image="workspaces/global/kernelImages/python",
kernel_template="workspaces/global/kernelTemplates/large",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python-xl",
display_name="Python [XL]",
kernel_image="workspaces/global/kernelImages/python",
kernel_template="workspaces/global/kernelTemplates/large",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="r",
display_name="R",
kernel_image="workspaces/global/kernelImages/r",
kernel_template="workspaces/global/kernelTemplates/small",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python-spark",
display_name="Spark - Python",
kernel_image="workspaces/global/kernelImages/python-spark",
kernel_template="workspaces/global/kernelTemplates/medium",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="r-spark",
display_name="Spark - R",
kernel_image="workspaces/global/kernelImages/r-spark",
kernel_template="workspaces/global/kernelTemplates/medium",
)
]
clients.notebook_kernel_spec_client.apply_notebook_kernel_specs(notebook_kernel_specs)
Applying Kernel Images, Templates, and Specs
To avoid conflicts, you can apply the kernel images, templates, and specs in a single transaction. This will delete all existing kernel images, templates, and specs and replace them with the provided lists.
import h2o_notebook
clients = h2o_notebook.login()
kernel_images = [
# ...
]
kernel_templates = [
# ...
]
notebook_kernel_specs = [
# ...
]
clients.notebook_kernel_spec_client.apply_kernel_images_templates_notebook_specs(
kernel_image_configs=kernel_images,
kernel_template_configs=kernel_templates,
notebook_kernel_spec_configs=notebook_kernel_specs
)
- Submit and view feedback for this page
- Send feedback about H2O Notebook Labs to cloud-feedback@h2o.ai