Skip to content

Commit

Permalink
feat(bid-script): support setting price per specific GPU model requested
Browse files Browse the repository at this point in the history
  • Loading branch information
andy108369 committed Sep 19, 2023
1 parent b0148f1 commit 373396f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 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
43 changes: 38 additions & 5 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,8 +113,6 @@ 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
##
Expand All @@ -129,11 +127,46 @@ 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
TARGET_GPU_UNIT="${PRICE_TARGET_GPU_UNIT:-100}" # USD/GPU unit a 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

#declare -A gpu_mappings=(
#["a100"]=120
#["t4"]=100)

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 +178,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
6 changes: 3 additions & 3 deletions charts/akash-provider/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ spec:
- name: PRICE_TARGET_IP
value: "{{ .Values.price_target_ip }}"
{{- end }}
{{ if .Values.price_target_gpu_unit }}
- name: PRICE_TARGET_GPU_UNIT
value: "{{ .Values.price_target_gpu_unit }}"
{{ 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 373396f

Please sign in to comment.