Skip to content

Commit

Permalink
feat(bid-script): support setting price per specific GPU model reques…
Browse files Browse the repository at this point in the history
…ted and parametrize price targets via helm chart values (#226)

* feat(bid-script): parametrize price targets via helm chart values

* feat(bid-script): support setting price per specific GPU model requested
  • Loading branch information
andy108369 authored Sep 19, 2023
1 parent 344331f commit 38bf25f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 14 deletions.
2 changes: 1 addition & 1 deletion charts/akash-provider/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type: application
# Versions are expected to follow Semantic Versioning (https://semver.org/)

# Major version bit highlights the mainnet release (e.g. mainnet4 = 4.x.x, mainnet5 = 5.x.x, ...)
version: 6.0.4
version: 6.0.5

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
55 changes: 42 additions & 13 deletions charts/akash-provider/scripts/price_script_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: the runtime of this script should NOT exceed 5 seconds! (Perhaps can be amended via AKASH_BID_PRICE_SCRIPT_PROCESS_TIMEOUT env variable)
# Requirements:
# curl jq bc mawk ca-certificates
# Version: Sept-08-2023
# Version: Sept-19-2023
set -o pipefail

# Example:
Expand Down Expand Up @@ -113,27 +113,56 @@ ssd_pers_storage_requested=$(echo "$data_in" | jq -r '[.[] | (.storage[] | selec
nvme_pers_storage_requested=$(echo "$data_in" | jq -r '[.[] | (.storage[] | select(.class == "beta3").size // 0) * .count] | add / pow(1024; 3)' | awk '{printf "%.12f\n", $0}')
ips_requested=$(echo "$data_in" | jq -r '(map(.ip_lease_quantity//0 * .count) | add)')
endpoints_requested=$(echo "$data_in" | jq -r '(map(.endpoint_quantity//0 * .count) | add)')
gpu_units_requested=$(echo "$data_in" | jq -r '[.[] | (.gpu.units // 0) * .count] | add')


# Provider sets the Price he wants to charge in USD/month
##
# Examples:
# Hetzner: CPX51 with 16CPU, 32RAM, 360GB disk = $65.81
# Akash: `(1.60*16)+(0.80*32)+(0.04*360)` = $65.60
TARGET_CPU="1.60" # USD/thread-month
TARGET_MEMORY="0.80" # USD/GB-month
TARGET_HD_EPHEMERAL="0.02" # USD/GB-month
TARGET_HD_PERS_HDD="0.01" # USD/GB-month (beta1)
TARGET_HD_PERS_SSD="0.03" # USD/GB-month (beta2)
TARGET_HD_PERS_NVME="0.04" # USD/GB-month (beta3)
TARGET_ENDPOINT="0.05" # USD for port/month
TARGET_IP="5" # USD for IP/month
TARGET_GPU_UNIT="100" # USD/GPU unit a month
TARGET_CPU="${PRICE_TARGET_CPU:-1.60}" # USD/thread-month
TARGET_MEMORY="${PRICE_TARGET_MEMORY:-0.80}" # USD/GB-month
TARGET_HD_EPHEMERAL="${PRICE_TARGET_HD_EPHEMERAL:-0.02}" # USD/GB-month
TARGET_HD_PERS_HDD="${PRICE_TARGET_HD_PERS_HDD:-0.01}" # USD/GB-month (beta1)
TARGET_HD_PERS_SSD="${PRICE_TARGET_HD_PERS_SSD:-0.03}" # USD/GB-month (beta2)
TARGET_HD_PERS_NVME="${PRICE_TARGET_HD_PERS_NVME:-0.04}" # USD/GB-month (beta3)
TARGET_ENDPOINT="${PRICE_TARGET_ENDPOINT:-0.05}" # USD for port/month
TARGET_IP="${PRICE_TARGET_IP:-5}" # USD for leased IP/month

## Example: restrict deployment requests that have services with less 0.1 threads
##echo "$data_in" | jq -r '.[].cpu <= 100' | grep -wq true && { echo -n "$AKASH_OWNER requested deployment with less than 0.1 threads. Aborting!" >&2; exit 1; }

# GPU pricing per GPU model (USD/GPU unit a month) calculation
##

# Populate the price target gpu_mappings dynamically based on the "price_target_gpu_mappings" value passed by the helm-chart
# Default: "a100=120,t4=80,*=130"
declare -A gpu_mappings=()

IFS=',' read -ra PAIRS <<< "${PRICE_TARGET_GPU_MAPPINGS:-a100=120,t4=80,*=130}"
for pair in "${PAIRS[@]}"; do
IFS='=' read -ra KV <<< "$pair"
key="${KV[0]}"
value="${KV[1]}"
gpu_mappings["$key"]=$value
done

gpu_price_total=0

while IFS= read -r resource; do
model=$(echo "$resource" | jq -r '.gpu.attributes.vendor.nvidia.model // 0')
gpu_units=$(echo "$resource" | jq -r '.gpu.units // 0')
# default to 100 USD/GPU per unit a month when PRICE_TARGET_GPU_MAPPINGS is not set
price="${gpu_mappings[''$model'']:-100}"
((gpu_price_total += gpu_units * price))

## DEBUG
#echo "model $model"
#echo "price for this model $price"
#echo "gpu_units $gpu_units"
#echo "gpu_price_total $gpu_price_total"
#echo ""
done <<< "$(echo "$data_in" | jq -rc '.[]')"

# Calculate the total resource cost for the deployment request in USD
##
total_cost_usd_target=$(bc -l <<< "( \
Expand All @@ -145,7 +174,7 @@ total_cost_usd_target=$(bc -l <<< "( \
($nvme_pers_storage_requested * $TARGET_HD_PERS_NVME) + \
($endpoints_requested * $TARGET_ENDPOINT) + \
($ips_requested * $TARGET_IP) + \
($gpu_units_requested * $TARGET_GPU_UNIT) \
($gpu_price_total) \
)")

# average block time: 6.117 seconds (based on the time diff between 8090658-8522658 heights [with 432000 blocks as a shift in between if considering block time is 6.0s "(60/6)*60*24*30"])
Expand Down
36 changes: 36 additions & 0 deletions charts/akash-provider/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,42 @@ spec:
{{ if .Values.debug_bid_script }}
- name: DEBUG_BID_SCRIPT
value: "{{ .Values.debug_bid_script }}"
{{- end }}
{{ if .Values.price_target_cpu }}
- name: PRICE_TARGET_CPU
value: "{{ .Values.price_target_cpu }}"
{{- end }}
{{ if .Values.price_target_memory }}
- name: PRICE_TARGET_MEMORY
value: "{{ .Values.price_target_memory }}"
{{- end }}
{{ if .Values.price_target_hd_ephemeral }}
- name: PRICE_TARGET_HD_EPHEMERAL
value: "{{ .Values.price_target_hd_ephemeral }}"
{{- end }}
{{ if .Values.price_target_hd_pers_hdd }}
- name: PRICE_TARGET_HD_PERS_HDD
value: "{{ .Values.price_target_hd_pers_hdd }}"
{{- end }}
{{ if .Values.price_target_hd_pers_ssd }}
- name: PRICE_TARGET_HD_PERS_SSD
value: "{{ .Values.price_target_hd_pers_ssd }}"
{{- end }}
{{ if .Values.price_target_hd_pers_nvme }}
- name: PRICE_TARGET_HD_PERS_NVME
value: "{{ .Values.price_target_hd_pers_nvme }}"
{{- end }}
{{ if .Values.price_target_endpoint }}
- name: PRICE_TARGET_ENDPOINT
value: "{{ .Values.price_target_endpoint }}"
{{- end }}
{{ if .Values.price_target_ip }}
- name: PRICE_TARGET_IP
value: "{{ .Values.price_target_ip }}"
{{- end }}
{{ if .Values.price_target_gpu_mappings }}
- name: PRICE_TARGET_GPU_MAPPINGS
value: "{{ .Values.price_target_gpu_mappings }}"
{{- end }}
- name: AKASH_BID_PRICE_CPU_SCALE
value: "{{ .Values.bidpricecpuscale }}"
Expand Down

0 comments on commit 38bf25f

Please sign in to comment.