...
You should see the lambda-stack
image in the list, this is the one we will use for now.
To start a program in the a container using this image, use the docker run --rm
command:
...
Add packages to the container
The container image may not have all the packages you need. To add more packages, you can create a new container image based on the LambdaStack one.
To create a container image, you need a Dockerfile
definition file. It contains the information about the base container image and the installations installation instructions for the additional packages.
...
Code Block | ||
---|---|---|
| ||
FROM lambda-stack:20.04
RUN pip install pip install transformers[torch] |
To build the corresponding container image, first create an empty folder and save the Dockerfile
in it:
...
then use the docker build
command to generate the new container image:
Code Block | ||
---|---|---|
| ||
$ cd hugging_container $ docker build -t pytorch-transformers . |
The -t
flag is used to tag the container image, making it easier to find and use it later.
...
You can now use it in place of the LambdaStack containerimage:
Code Block |
---|
$ docker run --rm pytorch-transformers \ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('I love you'))" libibverbs: Warning: couldn't open config directory '/etc/libibverbs.d'. libibverbs: Warning: couldn't open config directory '/etc/libibverbs.d'. No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english). Using a pipeline without specifying a model name and revision in production is not recommended. Downloading config.json: 100%|██████████| 629/629 [00:00<00:00, 1.45MB/s] Downloading pytorch_model.bin: 100%|██████████| 255M/255M [00:10<00:00, 24.5MB/s] Downloading tokenizer_config.json: 100%|██████████| 48.0/48.0 [00:00<00:00, 72.8kB/s] Downloading vocab.txt: 100%|██████████| 226k/226k [00:00<00:00, 295kB/s] [{'label': 'POSITIVE', 'score': 0.9998656511306763}] |
Containers Container images can be deleted using the docker image rm
command. For example, remove the pytorch-transformers
container image as follows:
Code Block |
---|
$ docker image rm pytorch-transformers Untagged: pytorch-transformers:latest Deleted: sha256:432c6be0a999484db090c5d9904e5c783454080d8ad8bc39e0499ace479c4559 Deleted: sha256:623ae3b33709c2fc4c40bc2c3959049345fee0087d39b4f53eb95aefd1c16f7d |
...