mirror of
https://github.com/karpathy/nanochat.git
synced 2025-12-06 12:22:18 +00:00
Optimize print0 function: Cache DDP rank evaluation for better performance
Refactor print0 function to conditionally define behavior based on DDP rank.
This commit is contained in:
parent
2e9669e03a
commit
ce64059d65
|
|
@ -18,10 +18,17 @@ import os
|
|||
import sys
|
||||
from ast import literal_eval
|
||||
|
||||
# Determine at import time which function to use
|
||||
_ddp_rank = int(os.environ.get('RANK', 0))
|
||||
|
||||
if _ddp_rank == 0:
|
||||
# On rank 0: print0 is just print
|
||||
def print0(s="", **kwargs):
|
||||
ddp_rank = int(os.environ.get('RANK', 0))
|
||||
if ddp_rank == 0:
|
||||
print(s, **kwargs)
|
||||
else:
|
||||
# On other ranks: print0 is a no-op
|
||||
def print0(s="", **kwargs):
|
||||
pass
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
if '=' not in arg:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user