Back to the course

Course artifact

Inference unit-economics calculator

A small calculator for capacity cost, utilization, price, and gross-margin sensitivity.

labs/unit_economics.pyPrivate course toolkit
#!/usr/bin/env python3
"""Editable inference unit-economics calculator."""
import argparse, json
if __name__=="__main__":
    p=argparse.ArgumentParser()
    p.add_argument("--gpu-hour",type=float,required=True)
    p.add_argument("--tokens-per-second",type=float,required=True)
    p.add_argument("--utilization",type=float,required=True)
    p.add_argument("--price-per-million",type=float,required=True)
    p.add_argument("--other-variable-cost",type=float,default=.08,help="Per 1M successful tokens")
    a=p.parse_args()
    effective=a.tokens_per_second*a.utilization
    compute=a.gpu_hour/effective/3600*1_000_000
    total=compute+a.other_variable_cost
    margin=1-total/a.price_per_million
    print(json.dumps({"effective_tokens_per_gpu_second":round(effective,2),
      "compute_cogs_per_million":round(compute,4),"total_variable_cogs_per_million":round(total,4),
      "revenue_per_million":a.price_per_million,"gross_margin":round(margin,4)},indent=2))