BLOGLLM Logo
Go Pro
Guest
Not signed in
All BlogsCoursesPracticeInterview prepSeriesTagsBookmarksPricing
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboardGames
Articles
Practice / Real-world constraints3 of 10 in topic

888. How many tokens can my budget train?

EasyReal-world constraints

Why it matters Founders and research leads ask this before every training run: what can this budget buy? The 6ND rule is the standard back-of-envelope answer.

Training a dense transformer costs about 6 * N * D FLOPs, where N is the parameter count and D the number of training tokens (forward plus backward pass).

Write training_budget(params, budget_usd, gpu_hourly_usd, peak_tflops, mfu, n_gpus).
- GPU hours you can buy: budget_usd / gpu_hourly_usd
- FLOPs delivered: gpu_hours * 3600 * peak_tflops * 1e12 * mfu (mfu is model FLOPs utilisation, a fraction in (0, 1])
- tokens: floor(FLOPs / (6 * params))
- wall-clock days on n_gpus GPUs: gpu_hours / n_gpus / 24

Return a dict {"gpu_hours": rounded to 1 decimal, "tokens": int, "tokens_per_param": tokens / params rounded to 1 decimal, "wall_days": rounded to 2 decimals}.

Functiondef training_budget(params, budget_usd, gpu_hourly_usd, peak_tflops, mfu, n_gpus)

Example 1

Input: training_budget(1e9, 10000, 2.5, 989, 0.4, 8)

Output: {'gpu_hours': 4000.0, 'tokens': 949440000000, 'tokens_per_param': 949.4, 'wall_days': 20.83}

Example 2

Input: params = 125000000, budget_usd = 500, gpu_hourly_usd = 1.0, peak_tflops = 312, mfu = 0.5, n_gpus = 1

Output: {'gpu_hours': 500.0, 'tokens': 374400000000, 'tokens_per_param': 2995.2, 'wall_days': 20.83}

Example 3

Input: params = 7e9, budget_usd = 200000, gpu_hourly_usd = 2.0, peak_tflops = 989, mfu = 0.35, n_gpus = 64

Output: {'gpu_hours': 100000.0, 'tokens': 2967000000000, 'tokens_per_param': 423.9, 'wall_days': 65.1}

Constraints

  • Python 3 standard library. Code runs in your browser.
  • Your code must pass all 4 tests to be accepted.
Hint 1

GPU hours first, then FLOPs, then tokens.

Hint 2

Use math.floor for tokens.

Hint 3

Wall days divide by the number of GPUs and by 24.

Common mistakes
  • Using 2ND (forward only).
  • Forgetting the 1e12 for TFLOPS.
  • Multiplying by n_gpus twice.
Understand the idea

Each token costs about 2N FLOPs forward and 4N backward. Real GPUs reach only part of their peak, measured as MFU; 35 to 50 percent is typical for well-tuned dense training. With $10,000 at $2.50 an hour you get 4000 GPU hours; at 989 TFLOPS and 40 percent MFU that is about 5.7e21 FLOPs, enough for about 949 billion tokens on a 1B model.

Shapes and data flow
Scalars in, dict out.
Topics
Real-world constraints
Similar questions
  • Self-host or pay per token?Easy
  • How many eval examples can you afford?Easy
  • Cheapest GPU fleet that meets throughput and memoryMedium
  • Largest decode batch under a latency SLOMedium
All Real-world constraints problems
Report
888 / 903
Python 3solution.pyPython idle
1
2
3
4
5
import math
def training_budget(params, budget_usd, gpu_hourly_usd, peak_tflops, mfu, n_gpus):
# your code here
pass
​

Run checks these cases in your browser, no sign-in needed. Submit checks all 4 tests.

Ctrl/Cmd + Enter to run
© BlogLLM, Bengaluru, IndiaAboutTermsPrivacyRefundsDMCAContactRSS