Skip to content

Commit

Permalink
[doc] use tqdm from tqdm.auto (#7191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhett-Ying committed Mar 4, 2024
1 parent 69247f5 commit 1547bd9
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions notebooks/stochastic_training/link_prediction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@
},
"outputs": [],
"source": [
"import tqdm\n",
"from tqdm.auto import tqdm\n",
"for epoch in range(3):\n",
" model.train()\n",
" total_loss = 0\n",
" for step, data in tqdm.tqdm(enumerate(create_train_dataloader())):\n",
" for step, data in tqdm(enumerate(create_train_dataloader())):\n",
" # Get node pairs with labels for loss calculation.\n",
" compacted_pairs, labels = data.node_pairs_with_labels\n",
" node_feature = data.node_features[\"feat\"]\n",
Expand Down Expand Up @@ -306,7 +306,7 @@
"\n",
"logits = []\n",
"labels = []\n",
"for step, data in tqdm.tqdm(enumerate(eval_dataloader)):\n",
"for step, data in tqdm(enumerate(eval_dataloader)):\n",
" # Get node pairs with labels for loss calculation.\n",
" compacted_pairs, label = data.node_pairs_with_labels\n",
"\n",
Expand Down Expand Up @@ -370,4 +370,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
6 changes: 3 additions & 3 deletions notebooks/stochastic_training/node_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@
},
"outputs": [],
"source": [
"import tqdm\n",
"from tqdm.auto import tqdm\n",
"\n",
"for epoch in range(10):\n",
" model.train()\n",
"\n",
" with tqdm.tqdm(train_dataloader) as tq:\n",
" with tqdm(train_dataloader) as tq:\n",
" for step, data in enumerate(tq):\n",
" x = data.node_features[\"feat\"]\n",
" labels = data.labels\n",
Expand All @@ -328,7 +328,7 @@
"\n",
" predictions = []\n",
" labels = []\n",
" with tqdm.tqdm(valid_dataloader) as tq, torch.no_grad():\n",
" with tqdm(valid_dataloader) as tq, torch.no_grad():\n",
" for data in tq:\n",
" x = data.node_features[\"feat\"]\n",
" labels.append(data.labels.cpu().numpy())\n",
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/data/lrgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pandas as pd
from ogb.utils import smiles2graph as smiles2graph_OGB
from tqdm import tqdm
from tqdm.auto import tqdm

from .. import backend as F

Expand Down
2 changes: 1 addition & 1 deletion python/dgl/data/superpixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
from scipy.spatial.distance import cdist
from tqdm import tqdm
from tqdm.auto import tqdm

from .. import backend as F
from ..convert import graph as dgl_graph
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np
import requests
from tqdm import tqdm
from tqdm.auto import tqdm

from .. import backend as F
from .graph_serialize import load_graphs, load_labels, save_graphs
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/nn/pytorch/explain/gnnexplainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch

from torch import nn
from tqdm import tqdm
from tqdm.auto import tqdm

from ....base import EID, NID
from ....subgraph import khop_in_subgraph
Expand Down
5 changes: 3 additions & 2 deletions python/dgl/nn/pytorch/network_emb.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Network Embedding NN Modules"""

# pylint: disable= invalid-name

import random

import torch
import torch.nn.functional as F
import tqdm
from torch import nn
from torch.nn import init
from tqdm.auto import trange

from ...base import NID
from ...convert import to_heterogeneous, to_homogeneous
Expand Down Expand Up @@ -340,7 +341,7 @@ def __init__(
num_nodes_total = hg.num_nodes()
node_frequency = torch.zeros(num_nodes_total)
# random walk
for idx in tqdm.trange(hg.num_nodes(node_metapath[0])):
for idx in trange(hg.num_nodes(node_metapath[0])):
traces, _ = random_walk(g=hg, nodes=[idx], metapath=metapath)
for tr in traces.cpu().numpy():
tr_nids = [
Expand Down
2 changes: 2 additions & 0 deletions script/dgl_dev.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ dependencies:
- clang-format
- pylint
- lintrunner
- jupyterlab
- ipywidgets
variables:
DGL_HOME: __DGL_HOME__
2 changes: 1 addition & 1 deletion tutorials/models/4_old_wines/7_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@
#
# .. code:: python
#
# from tqdm import tqdm
# from tqdm.auto import tqdm
# import torch as th
# import numpy as np
#
Expand Down
7 changes: 3 additions & 4 deletions tutorials/multi/2_node_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""


######################################################################
# Importing Packages
# ---------------
Expand All @@ -42,9 +41,9 @@
import torch.nn as nn
import torch.nn.functional as F
import torchmetrics.functional as MF
import tqdm
from torch.distributed.algorithms.join import Join
from torch.nn.parallel import DistributedDataParallel as DDP
from tqdm.auto import tqdm


######################################################################
Expand Down Expand Up @@ -155,7 +154,7 @@ def evaluate(rank, model, graph, features, itemset, num_classes, device):
is_train=False,
)

for data in tqdm.tqdm(dataloader) if rank == 0 else dataloader:
for data in tqdm(dataloader) if rank == 0 else dataloader:
blocks = data.blocks
x = data.node_features["feat"]
y.append(data.labels)
Expand Down Expand Up @@ -212,7 +211,7 @@ def train(
total_loss = torch.tensor(0, dtype=torch.float, device=device)
num_train_items = 0
with Join([model]):
for data in tqdm.tqdm(dataloader) if rank == 0 else dataloader:
for data in tqdm(dataloader) if rank == 0 else dataloader:
# The input features are from the source nodes in the first
# layer's computation graph.
x = data.node_features["feat"]
Expand Down

0 comments on commit 1547bd9

Please sign in to comment.