Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bid-script): use highest price when model detection fails #236

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.6
version: 6.0.7

# 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
38 changes: 26 additions & 12 deletions charts/akash-provider/scripts/price_script_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ function get_akt_price {
# bid script starts reading the deployment order request specs here (passed by the Akash Provider)
data_in=$(jq .)

## DEBUG
if ! [[ -z $DEBUG_BID_SCRIPT ]]; then
if ! [[ -z $DEBUG_BID_SCRIPT ]] && ! [[ -z $AKASH_OWNER ]]; then
echo "====================== start ======================" >> /tmp/${AKASH_OWNER}.log
echo "$(TZ=UTC date -R)" >> /tmp/${AKASH_OWNER}.log
echo "$data_in" >> /tmp/${AKASH_OWNER}.log
Expand Down Expand Up @@ -135,32 +134,43 @@ TARGET_IP="${PRICE_TARGET_IP:-5}" # USD for leased IP/mon
##

# 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}"
IFS=',' read -ra PAIRS <<< "${PRICE_TARGET_GPU_MAPPINGS}"
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
# Default to 100 USD/GPU per unit a month when PRICE_TARGET_GPU_MAPPINGS is not set
# Or use the highest price from PRICE_TARGET_GPU_MAPPINGS when model detection fails (ref. https://github.com/akash-network/support/issues/139 )
gpu_unit_max_price=100
for value in "${gpu_mappings[@]}"; do
if (( value > gpu_unit_max_price )); then
gpu_unit_max_price=$value
fi
done

if ! [[ -z $DEBUG_BID_SCRIPT ]]; then
echo "DEBUG: gpu_unit_max_price $gpu_unit_max_price"
fi

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}"
price="${gpu_mappings[''$model'']:-$gpu_unit_max_price}"
((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 ""
if ! [[ -z $DEBUG_BID_SCRIPT ]]; then
echo "DEBUG: model $model"
echo "DEBUG: price for this model $price"
echo "DEBUG: gpu_units $gpu_units"
echo "DEBUG: gpu_price_total $gpu_price_total"
fi
done <<< "$(echo "$data_in" | jq -rc '.[]')"

# Calculate the total resource cost for the deployment request in USD
Expand All @@ -177,6 +187,10 @@ total_cost_usd_target=$(bc -l <<< "( \
($gpu_price_total) \
)")

if ! [[ -z $DEBUG_BID_SCRIPT ]]; then
echo "DEBUG: Total cost USD/month: $total_cost_usd_target"
fi

# 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"])
# average number of days in a month: 30.437
# (60/6.117)*24*60*30.437 = 429909 blocks per month
Expand Down
Loading