Skip to content

Commit

Permalink
change MATIC to POL
Browse files Browse the repository at this point in the history
also POLs - to POL
and some autmoatic formating
  • Loading branch information
jalas167 committed Sep 20, 2024
1 parent aa27258 commit 9301fbb
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 173 deletions.
180 changes: 94 additions & 86 deletions src/pages/docs/creators/golem-workers/sd-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,97 +5,101 @@ description: Step-by-step instructions on how to run automatic1111 with a Stable

type: Article
---

# Stable diffusion usage example

In this example, we’ll show you how to run a sample [Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui)
In this example, we’ll show you how to run a sample [Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui)
(from [modelserve AI](https://modelserve.ai)) image using Golem-Workers.

## Prerequisites

We will be using **`curl`** to interact with the Golem-Workers API, which runs on **localhost:8000**
We will be using **`curl`** to interact with the Golem-Workers API, which runs on **localhost:8000**
(see [Getting started](/docs/creators/golem-workers/getting-started) if it is not).
All API requests will use **JSON data** to configure and manage the Golem-Workers service.

The JSON files used in this article can be found in the repository under the directory **`examples/sd-example`**.
The JSON files used in this article can be found in the repository under the directory **`examples/sd-example`**.
**Make sure** you run the `curl` commands from within this repository to ensure the paths to the JSON files are correct.

Feel free to experiment and modify the JSON files if you’d like to adjust configurations or explore different setups.

## 1. Top up your account

This article demonstrates how to rent a **mainnet GPU node**.
Mainnet payments on the Golem Network are processed using the [Polygon](https://polygon.technology) blockchain.
To proceed, you’ll need both **GLM** and **MATIC** tokens.
This article demonstrates how to rent a **mainnet GPU node**.
Mainnet payments on the Golem Network are processed using the [Polygon](https://polygon.technology) blockchain.
To proceed, you’ll need both **GLM** and **POL** tokens.

To top up your account, run the following command to generate a link to the **Golem Onboarding Portal**,
To top up your account, run the following command to generate a link to the **Golem Onboarding Portal**,
which contains all the instructions and explanations you’ll need:

```bash
docker compose exec golem-node yagna payment fund --network polygon
```
In Docker, the command may not open the link automatically,

In Docker, the command may not open the link automatically,
so copy the generated link and paste it into your browser to access the onboarding portal.

Drop the `docker compose exec golem-node` prefix if you are running
Drop the `docker compose exec golem-node` prefix if you are running
Golem-Workers [manually](/docs/creators/golem-workers/getting-started#manual)

For more details on mainnet payments on the Golem Network,
For more details on mainnet payments on the Golem Network,
check out [the article](/docs/creators/javascript/guides/switching-to-mainnet).

## 2. Create a cluster

In this step, create a cluster with any name you choose (`cluster_id`). For example: `example`.

```bash
curl --location 'http://localhost:8000/create-cluster' \
--header 'Content-Type: application/json' \
--data @create-cluster.json
--data @create-cluster.json
```

This is the json file you have just used (also available on
This is the json file you have just used (also available on
[GitHub](https://github.com/golemfactory/golem-workers/raw/main/examples/sd-example/create-cluster.json)):

```json
{
"cluster_id": "example",
"payment_config": {
"network": "polygon"
},
"budget_types": {
"default": {
"budget": {
"golem_workers.budgets.AveragePerCpuUsageLinearModelBudget": {
"average_cpu_load": 1,
"average_duration_hours": 0.5,
"average_max_cost": 1.5
}
},
"scope": "cluster"
}
},
"network_types": {
"default": {
"ip": "192.168.0.1/16"
"cluster_id": "example",
"payment_config": {
"network": "polygon"
},
"budget_types": {
"default": {
"budget": {
"golem_workers.budgets.AveragePerCpuUsageLinearModelBudget": {
"average_cpu_load": 1,
"average_duration_hours": 0.5,
"average_max_cost": 1.5
}
},
"node_types": {
"default": {
"market_config": {
"filters": [
{
"golem_reputation.ProviderBlacklistPlugin": {
"payment_network": "polygon"
}
}
],
"sorters": [
{
"golem_reputation.ReputationScorer": {
"payment_network": "polygon"
}
}
]
},
"scope": "cluster"
}
},
"network_types": {
"default": {
"ip": "192.168.0.1/16"
}
},
"node_types": {
"default": {
"market_config": {
"filters": [
{
"golem_reputation.ProviderBlacklistPlugin": {
"payment_network": "polygon"
}
}
}
],
"sorters": [
{
"golem_reputation.ReputationScorer": {
"payment_network": "polygon"
}
}
]
}
}
}
}
```

Expand All @@ -108,14 +112,14 @@ This is the json file you have just used (also available on
"network": "polygon"
},
```

The `network` property specifies the blockchain used for payments.
By default, this is set to `holesky`, which uses free test tokens to pay providers hosted by Golem.
This allows you to experiment before committing actual funds.

However, GPU nodes are only available on the mainnet, which operates on the [Polygon](https://polygon.technology) blockchain.
To rent these nodes, ensure that the network is set to `polygon`.


#### Default budget

```json
Expand All @@ -137,12 +141,14 @@ The `golem_workers.budgets.AveragePerCpuUsageLinearModelBudget` is a go-to budge
This budget model defines the maximum amount you're willing to pay for renting nodes based on estimated usage.

In this example, the configuration ensures that the node will not cost more than **1.5 GLM**, assuming that:

- The node will run for **0.5 hours**.
- On average, **1 CPU** will be actively used during that time.

You can specify multiple budget types, and select the appropriate one when creating individual nodes. If no specific budget is selected, the **`default`** budget type will be used automatically.

#### Default node type

```json
"node_types": {
"default": {
Expand All @@ -166,30 +172,31 @@ You can specify multiple budget types, and select the appropriate one when creat
}
```

The `golem_reputation.ProviderBlacklistPlugin` and `golem_reputation.ReputationScorer` are Golem-Workers components
that allow integration with the Golem Reputation service.
The `golem_reputation.ProviderBlacklistPlugin` and `golem_reputation.ReputationScorer` are Golem-Workers components
that allow integration with the Golem Reputation service.
These components help ensure that providers meet certain trust and performance criteria before being used.

In the following JSON configuration, the settings ensure that, regardless of how the node’s market configuration
is defined during specific node creation, both the provider blacklist and the public reputation score
In the following JSON configuration, the settings ensure that, regardless of how the node’s market configuration
is defined during specific node creation, both the provider blacklist and the public reputation score
will be considered when selecting a provider.

## 3. Create a node

Next, create a node based on the image
[scalepointai/automatic1111:4](https://registry.golem.network/explore/scalepointai/automatic1111)
and specify the path to the model
Next, create a node based on the image
[scalepointai/automatic1111:4](https://registry.golem.network/explore/scalepointai/automatic1111)
and specify the path to the model
(e.g. a precached on Golem Network proxy SD model `https://gpu-provider.dev.golem.network/models/v1-5-pruned-emaonly.safetensors` ).

```bash
curl --location 'http://localhost:8000/create-node' \
--header 'Content-Type: application/json' \
--data @create-node.json
--data @create-node.json
```

This is the json file you have just used (also available on
This is the json file you have just used (also available on
[GitHub](https://github.com/golemfactory/golem-workers/raw/main/examples/sd-example/create-node.json)):
```json

````json
{
"cluster_id": "example",
"node_networks": {
Expand Down Expand Up @@ -249,7 +256,7 @@ This is the json file you have just used (also available on

### `create-node` JSON explained

#### Node selection (`market_config`)
#### Node selection (`market_config`)
```json
"market_config": {
"demand": {
Expand All @@ -267,20 +274,19 @@ This is the json file you have just used (also available on
]
}
},
```
````

In this example, we are using the `vm-nvidia` runtime to obtain nodes with GPUs.
Additionally, we configure the node to allow downloading images from **Hugging Face** (which is available only on the testnet)
and our own **gpu-provider.dev.golem.network** proxy. The node will use the image
In this example, we are using the `vm-nvidia` runtime to obtain nodes with GPUs.
Additionally, we configure the node to allow downloading images from **Hugging Face** (which is available only on the testnet)
and our own **gpu-provider.dev.golem.network** proxy. The node will use the image
published to Golem Registry as [scalepointai/automatic1111](https://registry.golem.network/explore/scalepointai/automatic1111)
in version `4`.

This image includes a `start.sh` script that automatically downloads a model and starts the **Automatic1111 Web UI**.

For more details on configuring the market, see
For more details on configuring the market, see
[Create-Node Market Configuration](/docs/creators/golem-workers/create-node#market-configuration) section.


#### Service setup (`on_start_commands`)

```json
Expand All @@ -303,16 +309,16 @@ For more details on configuring the market, see
],
```

In this example, we set a **timeout of 60 minutes** for the image download and deployment.
While cached images typically don’t take that long, workers might need additional time to download
In this example, we set a **timeout of 60 minutes** for the image download and deployment.
While cached images typically don’t take that long, workers might need additional time to download
the entire image before they can begin executing tasks, which can be time-consuming.

We also configure **SSH** so that you can log in to the new node and manually interact with it if needed.

Finally, we execute the `start.sh` script, which is part of the image.
The script is provided with a link to a Stable Diffusion (SD) model stored on the Golem dev proxy.
(For your own use case, it's recommended to include the **model directly in the image**.
By doing this, the model is downloaded from the **Golem Registry** in one piece,
Finally, we execute the `start.sh` script, which is part of the image.
The script is provided with a link to a Stable Diffusion (SD) model stored on the Golem dev proxy.
(For your own use case, it's recommended to include the **model directly in the image**.
By doing this, the model is downloaded from the **Golem Registry** in one piece,
avoiding the need for additional accessing the internet after the node startup.

If you SSH into the worker, you should be able to view logs of the `start.sh` execution in the `/usr/src/app/output/log` file.
Expand Down Expand Up @@ -354,12 +360,13 @@ curl --location 'http://localhost:8000/get-node' \
--data @get-node.json
```

This is the json file you have just used (also available on
This is the json file you have just used (also available on
[GitHub](https://github.com/golemfactory/golem-workers/raw/main/examples/sd-example/get-node.json)):

```json
{
"cluster_id": "example",
"node_id": "node0"
"cluster_id": "example",
"node_id": "node0"
}
```

Expand All @@ -370,7 +377,8 @@ It returns the node’s state:
- `started` means the node is ready, the image is deployed, the commands `on_start_commands` have been run successfully

## 5. Send a request to the node and generate images
In the final step, launch a web browser and go to [http://localhost:8080/](http://localhost:8080).

In the final step, launch a web browser and go to [http://localhost:8080/](http://localhost:8080).
This will open the Automatic1111 GUI, where you can generate images.

![automatic1111 screenshot](/golem-workers/automatic1111.png)
Expand All @@ -382,11 +390,10 @@ To generate some images using the Automatic1111 GUI, you can either enter your p
1. (optional) Adjust any additional settings if needed, such as the number of steps, sampler type, or output dimensions.
1. Click the “Generate” button to produce the images.

#### Alternatively, use the automatic1111 API directly

#### Alternatively, use the automatic1111 API directly

Copy and run the following Python code (directly in the terminal or using a Jupyter Notebook).
The code is also availabla on
Copy and run the following Python code (directly in the terminal or using a Jupyter Notebook).
The code is also availabla on
[GitHub](https://github.com/golemfactory/golem-workers/raw/main/examples/sd-example/sd-inference.py).

```python
Expand Down Expand Up @@ -424,19 +431,20 @@ for i in range(1, 11):
This code will generate 10 images and save them to your computer.

## 6. Stop the cluster

After completing the testing, you can shut down the cluster, using the following command:

```bash
curl --location 'http://localhost:8000/delete-cluster' \
--header 'Content-Type: application/json' \
--data @delete-cluster.json
--data @delete-cluster.json
```

This is the json file you have just used (also available on
This is the json file you have just used (also available on
[GitHub](https://github.com/golemfactory/golem-workers/raw/main/examples/hello-example/delete-cluster.json)):

```json
{
"cluster_id": "example"
"cluster_id": "example"
}
```

Loading

0 comments on commit 9301fbb

Please sign in to comment.