rohitg00/ai-engineering-from-scratch · error · ValueError
batch_size must be > 0, got {batch_size}
Error message
batch_size must be > 0, got {batch_size} What it means
Error "batch_size must be > 0, got {batch_size}" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/49-lm-eval-harness/code/main.py:297
for ex in examples:
f.write(json.dumps({
"id": ex.id,
"prompt": ex.prompt,
"targets": ex.targets,
"metric": ex.metric,
**({"extras": ex.extras} if ex.extras else {}),
}) + "\n")
def run_task(
task_name: str,
examples: List[Example],
adapter: ModelAdapter,
*,
batch_size: int = 8,
) -> TaskResult:
if batch_size <= 0:
raise ValueError(f"batch_size must be > 0, got {batch_size}")
if not examples:
return TaskResult(task=task_name, metric="none", score=0.0, correct=0, total=0)
metric = examples[0].metric
assert all(ex.metric == metric for ex in examples), f"task {task_name} mixes metrics"
metric_fn = METRIC_FNS[metric]
per_example: List[Dict[str, object]] = []
correct_sum = 0.0
total = 0
start = time.perf_counter()
for i in range(0, len(examples), batch_size):
chunk = examples[i:i + batch_size]
prompts = [ex.prompt for ex in chunk]
outputs = adapter.generate(prompts)
if len(outputs) != len(chunk):
raise ValueError(
f"adapter returned {len(outputs)} outputs for {len(chunk)} prompts in task {task_name}"
)
for ex, out in zip(chunk, outputs, strict=True):View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/49-lm-eval-harness/code/main.py:297 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/6480d7af5aef14c6.
Report an issue: GitHub.