Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit cc0882d

Browse files
authored
logging nit, avoid explicit global use (#1548)
1 parent d81cea4 commit cc0882d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

torchdynamo/logging.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import logging
23
import os
34

@@ -23,7 +24,7 @@ def set_loggers_level(level):
2324
"version": 1,
2425
"formatters": {
2526
"torchdynamo_format": {
26-
"format": "%(name)s: [%(levelname)s] [%(asctime)s] %(message)s"
27+
"format": "[%(asctime)s] %(name)s: [%(levelname)s] %(message)s"
2728
},
2829
},
2930
"handlers": {
@@ -74,13 +75,11 @@ def init_logging(log_level, log_file_name=None):
7475
# def fn():
7576
# _step_logger()(logging.INFO, "msg")
7677

77-
_step_counter = 1
78+
_step_counter = itertools.count(1)
7879

7980

8081
def get_step_logger(logger):
81-
global _step_counter
82-
step = _step_counter
83-
_step_counter += 1
82+
step = next(_step_counter)
8483

8584
def log(level, msg):
8685
logger.log(level, f"Step {step}: {msg}")

torchinductor/compile_fx.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dataclasses
22
import functools
3+
import itertools
34
import logging
45
from typing import List
56

@@ -304,7 +305,7 @@ def is_not_gradout(x):
304305
return len(static_arg_idxs)
305306

306307

307-
_graph_counter = 0
308+
_graph_counter = itertools.count(0)
308309

309310

310311
def compile_fx(model_: torch.fx.GraphModule, example_inputs_: List[torch.Tensor]):
@@ -323,9 +324,7 @@ def compile_fx(model_: torch.fx.GraphModule, example_inputs_: List[torch.Tensor]
323324
num_example_inputs = len(example_inputs_)
324325
cudagraphs = BoxedBool(config.triton.cudagraphs)
325326

326-
global _graph_counter
327-
graph_id = _graph_counter
328-
_graph_counter += 1
327+
graph_id = next(_graph_counter)
329328

330329
@dynamo_utils.dynamo_timed
331330
def fw_compiler(model: torch.fx.GraphModule, example_inputs):

0 commit comments

Comments
 (0)