Skip to content

Containerize Notebooks

In this tutorial we will show how to use containerized notebooks using the chatgpt 2 model from hugging face.

Video

Video is still in development.

Requirement

Downloads

Setup

If you don't have a database, schema or warehouse yet.
use role sysadmin;

-- Create a database to store our schemas.
create database if not exists raw;

-- Create the schema. The schema stores all our objectss.
create schema if not exists raw.notebook;

/*
    Warehouses are synonymous with the idea of compute
    resources in other systems. We will use this
    warehouse to call our user defined function.
*/
create warehouse if not exists development 
    warehouse_size = xsmall
    initially_suspended = true;

use database raw;
use schema notebook;
use warehouse development;

GPU Compute Pool

First lets start by creating a gpu compute pool for our notebook via accountadmin role and then grant sysadmin to use it.

1
2
3
4
5
6
7
8
use role accountadmin;

create compute pool gpu_small
    min_nodes = 1
    max_nodes = 1
    instance_family = gpu_nv_s;

grant usage on compute pool gpu_small to role sysadmin;
Statement executed successfully.

External Access

Lets create the network rules in a worksheet to allow our Snowflake Notebook to talk with our external source.

use role sysadmin;

create or replace network rule pypi_network_rule
    mode = egress
    type = host_port
    value_list = ('pypi.org', 'pypi.python.org', 'pythonhosted.org',  'files.pythonhosted.org');

create or replace network rule hf_network_rule
        mode = egress
        type = host_port
        value_list = ('huggingface.co', 'cdn-lfs.huggingface.co','cdn-lfs.hf.co');

use role accountadmin;

create or replace external access integration pypi_access_integration
    allowed_network_rules = (pypi_network_rule)
    enabled = true;

create or replace external access integration hf_access_integration
    allowed_network_rules = (hf_network_rule)
    enabled = true;

grant usage on integration pypi_access_integration to role sysadmin;
grant usage on integration hf_access_integration to role sysadmin;
Statement executed successfully.

Notebook

You can not use accountadmin. Please switch to sysadmin role.

Lets start by setting our role to sysadmin. note

Setup

Upload the example notebook provided. note

Select Run on container, ML runtime and the gpu compute pool we created earlier. note

To enable external connection to pypi and hugging face we will need to go to notebook settings. note

Select External access. note

Enable both pypi and huggingface. note

Click run all, the notebook will provide you a timer. It typically takes 5-7 minutes. note

Result

Once the notebook runs you will see we first make a directory for files to be downloaded to. note

We then download the chatgpt 2 model and save it to our files folder. note

We finally use our model and gpu to provide a prompt and get a response back. note