{"record":{"id":"448fb4f0be6f1e02","repo":"rohitg00/ai-engineering-from-scratch","slug":"only-got-collected-world-size-results-result","errorCode":null,"errorMessage":"only got {collected}/{world_size} results: {results}","messagePattern":"only got (.+?)/(.+?) results: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/48-distributed-fsdp-ddp/code/main.py","lineNumber":352,"sourceCode":"    collected = 0\n    while collected < world_size and time.time() < deadline:\n        try:\n            rank, payload, diff = result_queue.get(timeout=1.0)\n        except Exception:\n            continue\n        results[rank] = payload\n        if diff > max_diff:\n            max_diff = diff\n        collected += 1\n    for p in procs:\n        p.join(timeout=max(1.0, deadline - time.time()))\n    if any(p.is_alive() for p in procs):\n        for p in procs:\n            if p.is_alive():\n                p.terminate()\n        raise RuntimeError(\"ranks did not finish in time\")\n    if collected < world_size:\n        raise RuntimeError(f\"only got {collected}/{world_size} results: {results}\")\n    for rank, payload in results.items():\n        if \"error\" in payload:\n            raise RuntimeError(f\"rank {rank} failed: {payload['error']}\")\n    param_sums = {r: results[r][\"post_param_sum\"] for r in results}\n    spread = max(param_sums.values()) - min(param_sums.values())\n    losses = [results[r][\"final_loss\"] for r in results]\n    grad_norm = results[0][\"grad_norm_after_all_reduce\"]\n    return {\n        \"world_size\": world_size,\n        \"backend\": backend,\n        \"param_sum_per_rank\": param_sums,\n        \"param_sum_spread\": spread,\n        \"losses\": losses,\n        \"grad_norm_after_all_reduce\": grad_norm,\n        \"manual_all_reduce_max_diff_vs_single_process\": max_diff,\n        \"fsdp_round_trip_all_ranks_ok\": all(results[r][\"fsdp_round_trip_ok\"] for r in results),\n    }\n","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/48-distributed-fsdp-ddp/code/main.py#L334-L370","documentation":"Post-join completeness check in the distributed demo: the timeout expired (or ranks crashed silently) and the result queue collected fewer payloads than world_size, so per-rank results are missing and gradients/weights cannot be compared.","triggerScenarios":"Thrown at phases/19-capstone-projects/48-distributed-fsdp-ddp/code/main.py:352 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the run with a larger timeout to rule out slow startup","Inspect the reported per-rank results dict to find which rank(s) failed to report","Log stderr from worker processes to surface the underlying crash"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}