File size: 6,164 Bytes
76d9c4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---
title: Stable Diffusion Playground
description: Launch an interactive web app for Stable Diffusion
icon: "circle-2"
version: EN
---

This example deploys a simple web app for Stable Diffusion. You will learn how you can set up an interactive workload for inference -- mounting models from Hugging Face and opening up a port for user inputs. For a more in-depth guide, refer to our [blog post](https://blog.vessl.ai/thin-plate-spline-motion-model-for-image-animation). 

<CardGroup cols={2}>
  <Card icon="sparkles" title="Try it on VESSL Hub"  href="https://vessl.ai/hub/ssd-1b-inference">
    Try out the Quickstart example with a single click on VESSL Hub.
  </Card>

  <Card icon="github" title="See the final code" href="https://github.com/vessl-ai/hub-model/tree/main/SSD-1B">
    See the completed YAML file and final code for this example. 
  </Card>
</CardGroup>

## What you will do

<img
  style={{ borderRadius: '0.5rem' }}
  src="/images/get-started/ssd-title.png"
/>

- Host a GPU-accelerated web app built with [Streamlit](https://streamlit.io/) 
- Mount model checkpoints from [Hugging Face](https://huggingface.co/)
- Open up a port to an interactive workload for inference

## Writing the YAML 

Let's fill in the `stable-diffusion.yml` file.

<Steps titleSize="h3">
  <Step title="Spin up an interactive workload">
    We already learned how you can launch an interactive workload in our [previous](/get-started/gpu-notebook) guide. Let's copy & paste the YAML we wrote for `notebook.yml`.

    ```yaml
    name: Stable Diffusion Playground
    description: An interactive web app for Stable Diffusion
    resources:
      cluster: vessl-gcp-oregon
      preset: gpu-l4-small
    image: quay.io/vessl-ai/torch:2.1.0-cuda12.2-r3
    interactive:
      jupyter:
        idle_timeout: 120m
      max_runtime: 24h
    ```
  </Step>

  <Step title="Configure an interactive run">
    Let's mount a [GitHub repo](https://github.com/vessl-ai/hub-model/tree/main/SSD-1B) and import a model checkpoint from Hugging Face. We already learned how you can mount a codebase from our [Quickstart](/get-started/quickstart) guide.  
    
    VESSL AI comes with a native integration with Hugging Face so you can import models and datasets simply by referencing the link to the Hugging Face repository. Under `import`, let's create a working directory `/model/` and import the [model](https://huggingface.co/VESSL/SSD-1B/tree/main). 

    ```yaml
    name: Stable Diffusion Playground
    description: An interactive web app for Stable Diffusion
    resources:
      cluster: vessl-gcp-oregon
      preset: gpu-l4-small
    image: quay.io/vessl-ai/torch:2.1.0-cuda12.2-r3
		import:
			/code/:
				git:
					url: https://github.com/vessl-ai/hub-model
					ref: main
			/model/: hf://huggingface.co/VESSL/SSD-1B
    interactive:
      jupyter:
        idle_timeout: 120m
      max_runtime: 24h
    ```
  </Step> 

  <Step title="Open up a port for inference">

    The `ports` key expose the workload ports where VESSL AI listens for HTTP requests. This means you will be able to interact with the remote workload -- sending input query and receiving an generated image through port `80` in this case. 

    ```yaml
    name: Stable Diffusion Playground
    description: An interactive web app for Stable Diffusion
    resources:
      cluster: vessl-gcp-oregon
      preset: gpu-l4-small
    image: quay.io/vessl-ai/torch:2.1.0-cuda12.2-r3
		import:
			/code/:
				git:
					url: https://github.com/vessl-ai/hub-model
					ref: main
			/model/: hf://huggingface.co/VESSL/SSD-1B
    interactive:
      jupyter:
        idle_timeout: 120m
      max_runtime: 24h
    ports:
      - name: streamlit
        type: http
        port: 80
    ```
  </Step>

    <Step title="Write the run commands">

    Let's install additional Python dependencies with [`requirements.txt`](https://github.com/vessl-ai/hub-model/blob/main/SSD-1B/requirements.txt) and finally run our app [`ssd_1b_streamlit.py`](https://github.com/vessl-ai/hub-model/blob/main/SSD-1B/ssd_1b_streamlit.py). 
    
    Here, we see how our Streamlit app is using the port we created previously with the `--server.port=80` flag. Through the port, the app receives a user input and generates an image with the Hugging Face model we mounted on `/model/`. 

    ```yaml
    name: Stable Diffusion Playground
    description: An interactive web app for Stable Diffusion
    resources:
      cluster: vessl-gcp-oregon
      preset: gpu-l4-small
    image: quay.io/vessl-ai/torch:2.1.0-cuda12.2-r3
    import:
      /code/:
        git:
          url: https://github.com/vessl-ai/hub-model
          ref: main
      /model/: hf://huggingface.co/VESSL/SSD-1B
    run:
      - command: |-
        pip install -r requirements.txt
        streamlit run ssd_1b_streamlit.py --server.port=80
        workdir: /code/SSD-1B
    interactive:
      max_runtime: 24h
      jupyter:
        idle_timeout: 120m
    ports:
      - name: streamlit
        type: http
        port: 80
    ```
  </Step>
</Steps>

## Running the app

Once again, running the workload will guide you to the workload Summary page. 

```
vessl run create -f stable-diffusion.yml
```

Under ENDPOINTS, click the `streamlit` link to launch the app. 

<img
  style={{ borderRadius: '0.5rem' }}
  src="/images/get-started/ssd-summary.jpeg"
/>

<img
  style={{ borderRadius: '0.5rem' }}
  src="/images/get-started/ssd-streamlit.jpeg"
/>

## Using our web interface

You can repeat the same process on the web. Head over to your [Organization](https://vessl.ai), select a project, and create a New run. 

<iframe 
  src="https://scribehow.com/embed/Stable_Diffusion_Playground__D9ujQM9ZQtGz_Aj9oiyXSg?skipIntro=true&removeLogo=true"
  width="100%" height="640" allowfullscreen frameborder="0"
  style={{ borderRadius: '0.5rem' }} >
</iframe>

## What's next?

See how VESSL AI takes care of the infrastructural challenges of fine-tuning a large language model with a custom dataset. 

<CardGroup cols={2}>
  <Card title="Llama 2 Fine-tuing" href="get-started/llama2">
    Launch an interactive web application for Stable Diffusion
  </Card>
</CardGroup>