Skip to content

Commit 1547bd9

Browse files
committed
[doc] use tqdm from tqdm.auto (#7191)
1 parent 69247f5 commit 1547bd9

File tree

10 files changed

+20
-18
lines changed

10 files changed

+20
-18
lines changed

notebooks/stochastic_training/link_prediction.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@
249249
},
250250
"outputs": [],
251251
"source": [
252-
"import tqdm\n",
252+
"from tqdm.auto import tqdm\n",
253253
"for epoch in range(3):\n",
254254
" model.train()\n",
255255
" total_loss = 0\n",
256-
" for step, data in tqdm.tqdm(enumerate(create_train_dataloader())):\n",
256+
" for step, data in tqdm(enumerate(create_train_dataloader())):\n",
257257
" # Get node pairs with labels for loss calculation.\n",
258258
" compacted_pairs, labels = data.node_pairs_with_labels\n",
259259
" node_feature = data.node_features[\"feat\"]\n",
@@ -306,7 +306,7 @@
306306
"\n",
307307
"logits = []\n",
308308
"labels = []\n",
309-
"for step, data in tqdm.tqdm(enumerate(eval_dataloader)):\n",
309+
"for step, data in tqdm(enumerate(eval_dataloader)):\n",
310310
" # Get node pairs with labels for loss calculation.\n",
311311
" compacted_pairs, label = data.node_pairs_with_labels\n",
312312
"\n",
@@ -370,4 +370,4 @@
370370
},
371371
"nbformat": 4,
372372
"nbformat_minor": 0
373-
}
373+
}

notebooks/stochastic_training/node_classification.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@
297297
},
298298
"outputs": [],
299299
"source": [
300-
"import tqdm\n",
300+
"from tqdm.auto import tqdm\n",
301301
"\n",
302302
"for epoch in range(10):\n",
303303
" model.train()\n",
304304
"\n",
305-
" with tqdm.tqdm(train_dataloader) as tq:\n",
305+
" with tqdm(train_dataloader) as tq:\n",
306306
" for step, data in enumerate(tq):\n",
307307
" x = data.node_features[\"feat\"]\n",
308308
" labels = data.labels\n",
@@ -328,7 +328,7 @@
328328
"\n",
329329
" predictions = []\n",
330330
" labels = []\n",
331-
" with tqdm.tqdm(valid_dataloader) as tq, torch.no_grad():\n",
331+
" with tqdm(valid_dataloader) as tq, torch.no_grad():\n",
332332
" for data in tq:\n",
333333
" x = data.node_features[\"feat\"]\n",
334334
" labels.append(data.labels.cpu().numpy())\n",

python/dgl/data/lrgb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pandas as pd
66
from ogb.utils import smiles2graph as smiles2graph_OGB
7-
from tqdm import tqdm
7+
from tqdm.auto import tqdm
88

99
from .. import backend as F
1010

python/dgl/data/superpixel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55
from scipy.spatial.distance import cdist
6-
from tqdm import tqdm
6+
from tqdm.auto import tqdm
77

88
from .. import backend as F
99
from ..convert import graph as dgl_graph

python/dgl/data/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import numpy as np
1414
import requests
15-
from tqdm import tqdm
15+
from tqdm.auto import tqdm
1616

1717
from .. import backend as F
1818
from .graph_serialize import load_graphs, load_labels, save_graphs

python/dgl/nn/pytorch/explain/gnnexplainer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import torch
66

77
from torch import nn
8-
from tqdm import tqdm
8+
from tqdm.auto import tqdm
99

1010
from ....base import EID, NID
1111
from ....subgraph import khop_in_subgraph

python/dgl/nn/pytorch/network_emb.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Network Embedding NN Modules"""
2+
23
# pylint: disable= invalid-name
34

45
import random
56

67
import torch
78
import torch.nn.functional as F
8-
import tqdm
99
from torch import nn
1010
from torch.nn import init
11+
from tqdm.auto import trange
1112

1213
from ...base import NID
1314
from ...convert import to_heterogeneous, to_homogeneous
@@ -340,7 +341,7 @@ def __init__(
340341
num_nodes_total = hg.num_nodes()
341342
node_frequency = torch.zeros(num_nodes_total)
342343
# random walk
343-
for idx in tqdm.trange(hg.num_nodes(node_metapath[0])):
344+
for idx in trange(hg.num_nodes(node_metapath[0])):
344345
traces, _ = random_walk(g=hg, nodes=[idx], metapath=metapath)
345346
for tr in traces.cpu().numpy():
346347
tr_nids = [

script/dgl_dev.yml.template

+2
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ dependencies:
4747
- clang-format
4848
- pylint
4949
- lintrunner
50+
- jupyterlab
51+
- ipywidgets
5052
variables:
5153
DGL_HOME: __DGL_HOME__

tutorials/models/4_old_wines/7_transformer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@
589589
#
590590
# .. code:: python
591591
#
592-
# from tqdm import tqdm
592+
# from tqdm.auto import tqdm
593593
# import torch as th
594594
# import numpy as np
595595
#

tutorials/multi/2_node_classification.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
2121
"""
2222

23-
2423
######################################################################
2524
# Importing Packages
2625
# ---------------
@@ -42,9 +41,9 @@
4241
import torch.nn as nn
4342
import torch.nn.functional as F
4443
import torchmetrics.functional as MF
45-
import tqdm
4644
from torch.distributed.algorithms.join import Join
4745
from torch.nn.parallel import DistributedDataParallel as DDP
46+
from tqdm.auto import tqdm
4847

4948

5049
######################################################################
@@ -155,7 +154,7 @@ def evaluate(rank, model, graph, features, itemset, num_classes, device):
155154
is_train=False,
156155
)
157156

158-
for data in tqdm.tqdm(dataloader) if rank == 0 else dataloader:
157+
for data in tqdm(dataloader) if rank == 0 else dataloader:
159158
blocks = data.blocks
160159
x = data.node_features["feat"]
161160
y.append(data.labels)
@@ -212,7 +211,7 @@ def train(
212211
total_loss = torch.tensor(0, dtype=torch.float, device=device)
213212
num_train_items = 0
214213
with Join([model]):
215-
for data in tqdm.tqdm(dataloader) if rank == 0 else dataloader:
214+
for data in tqdm(dataloader) if rank == 0 else dataloader:
216215
# The input features are from the source nodes in the first
217216
# layer's computation graph.
218217
x = data.node_features["feat"]

0 commit comments

Comments
 (0)