All problems
Max Batch Size From Memory
Problem
Find the largest batch that fits the memory left after loading the weights: floor((budget_bytes - model_bytes) / per_sequence_cache_bytes). Return 0 if weights exceed the budget or the per-sequence cache is non-positive.
The signature is max_batch_size(budget_bytes, model_bytes, per_sequence_cache_bytes). Return an integer.
Hint
Floor division gives the number of whole per-sequence caches that fit.
Test cases
case 1
in: [80000000000,40000000000,500000000]
expected: 80
case 2
in: [100000000000,99000000000,1000000000]
expected: 1
case 3
in: [1000000000,2000000000,1000]
expected: 0
case 4
in: [50000000000,0,2500000000]
expected: 20
Starter codePython
def max_batch_size(budget_bytes, model_bytes, per_sequence_cache_bytes):
# Your code here
pass4 test cases · run your code against them in the editor