AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(blocks/replicate): bump per-second rate to cover up to A100-80GB (#12956)
Zamil Majdy79c87e05d414
diff --git a/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py b/autogpt_platform/backend/backend/blocks/replicate/replicate_block.pyindex 041f78fe8e..c5fd114d40 100644--- a/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py+++ b/autogpt_platform/backend/backend/blocks/replicate/replicate_block.py@@ -27,12 +27,12 @@ from backend.util.exceptions import BlockExecutionError, BlockInputErrorlogger = logging.getLogger(__name__)-# Replicate hardware tier cost — most popular public models (Flux, SDXL,-# Llama 70B etc.) run on Nvidia L40S at $0.001400/sec. Using a single-# conservative mid-tier estimate is much better than a flat RUN charge,-# which under-bills long-running models by 10-500×. Heavier models run-# on A100 at $0.001400/sec; cheaper ones on L4 at $0.000275/sec.-_REPLICATE_USD_PER_SEC = 0.001400+# Replicate $/sec varies by hardware tier (CPU $0.000100 → 8×H100 $0.005600).+# The API doesn't return which tier ran the prediction, so we pick a single+# rate that covers up to A100-80GB ($0.001875/sec) without under-billing.+# Cheaper hardware (L40S/L4/T4) is over-billed slightly; multi-GPU configs+# are still under-billed but are rare in user-facing community models.+_REPLICATE_USD_PER_SEC = 0.002000class ReplicateModelBlock(Block):diff --git a/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.py b/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.pyindex b7bcff2d23..8f43fd29a3 100644--- a/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.py+++ b/autogpt_platform/backend/backend/blocks/replicate/replicate_block_cost_test.py@@ -32,14 +32,15 @@ def test_registered_as_cost_usd_150():def test_hardware_rate_constant_in_range():- """$0.0014/s is Nvidia L40S tier. Sanity-check we haven't accidentally- shipped a rate that's off by an order of magnitude (e.g. $0.014 would- 10x over-bill every run).+ """Sanity-check we haven't shipped a rate off by an order of magnitude+ (e.g. $0.02 would 10x over-bill every run).++ Replicate's hardware tiers span CPU $0.000100 → 8×H100 $0.005600. The+ flat rate must cover at least up to A100-80GB ($0.001875) to avoid+ under-billing single-GPU community models, without going so high that+ cheap-hardware users are over-billed by an order of magnitude."""- # Replicate's public hardware tiers: L4 $0.000275, A10G $0.000575,- # L40S $0.000975, A100 $0.001400, A100-80GB $0.001725. L40S @- # $0.0014/s covers most popular models with mild over-bill margin.- assert 0.0005 <= _REPLICATE_USD_PER_SEC <= 0.002+ assert 0.001875 <= _REPLICATE_USD_PER_SEC <= 0.0025def _make_fake_prediction(output, predict_time=None, status="succeeded", error=None):@@ -99,9 +100,8 @@ async def test_run_model_uses_model_keyword_when_ref_is_unpinned():@pytest.mark.asyncioasync def test_run_model_emits_provider_cost_from_predict_time():- """Core contract: provider_cost = predict_time * $0.0014/s, cost_usd."""+ """Core contract: provider_cost = predict_time * _REPLICATE_USD_PER_SEC, cost_usd."""block = ReplicateModelBlock()- # 5-second run → 5 * 0.0014 = $0.007 → 150 cr/$ * 0.007 ceil = 2 crprediction = _make_fake_prediction(output="result-data", predict_time=5.0)client = MagicMock()diff --git a/autogpt_platform/backend/backend/data/block_cost_config.py b/autogpt_platform/backend/backend/data/block_cost_config.pyindex f753863a4a..54e80cf28f 100644--- a/autogpt_platform/backend/backend/data/block_cost_config.py+++ b/autogpt_platform/backend/backend/data/block_cost_config.py@@ -680,13 +680,11 @@ BLOCK_COSTS: dict[Type[Block], list[BlockCost]] = {)],# ReplicateModelBlock is a generic wrapper — users pass ANY Replicate- # model ref. A flat 10 cr/run was:- # - 20x over-billing cheap models (~$0.005 SDXL tiny runs)- # - 10-500x under-billing long video/LLM runs ($1-$50+)- # Block now reads prediction.metrics.predict_time after completion- # and bills that × $0.0014/s (Nvidia L40S mid-tier) via COST_USD- # 150 cr/$. Heavy LLMs on A100 under-bill slightly, cheap L4 runs- # over-bill slightly, but the catastrophic under-bill is gone.+ # model ref. The block reads prediction.metrics.predict_time after+ # completion and bills predict_time × $/sec via COST_USD 150 cr/$.+ # Replicate's API doesn't expose hardware tier per prediction, so the+ # block uses a single $/sec rate sized to cover up to A100-80GB+ # without under-billing; cheaper hardware is over-billed slightly.ReplicateModelBlock: [BlockCost(cost_amount=150,