From 1547bd931d17cd1da144a6d38bb687c0f2c3b364 Mon Sep 17 00:00:00 2001 From: Rhett Ying <85214957+Rhett-Ying@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:43:15 +0800 Subject: [PATCH] [doc] use tqdm from tqdm.auto (#7191) --- notebooks/stochastic_training/link_prediction.ipynb | 8 ++++---- notebooks/stochastic_training/node_classification.ipynb | 6 +++--- python/dgl/data/lrgb.py | 2 +- python/dgl/data/superpixel.py | 2 +- python/dgl/data/utils.py | 2 +- python/dgl/nn/pytorch/explain/gnnexplainer.py | 2 +- python/dgl/nn/pytorch/network_emb.py | 5 +++-- script/dgl_dev.yml.template | 2 ++ tutorials/models/4_old_wines/7_transformer.py | 2 +- tutorials/multi/2_node_classification.py | 7 +++---- 10 files changed, 20 insertions(+), 18 deletions(-) diff --git a/notebooks/stochastic_training/link_prediction.ipynb b/notebooks/stochastic_training/link_prediction.ipynb index e8c68fe1fd3d..dc11bddd6716 100644 --- a/notebooks/stochastic_training/link_prediction.ipynb +++ b/notebooks/stochastic_training/link_prediction.ipynb @@ -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", @@ -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", @@ -370,4 +370,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/notebooks/stochastic_training/node_classification.ipynb b/notebooks/stochastic_training/node_classification.ipynb index b170cc5ba5d2..b21d479ab4aa 100644 --- a/notebooks/stochastic_training/node_classification.ipynb +++ b/notebooks/stochastic_training/node_classification.ipynb @@ -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", @@ -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", diff --git a/python/dgl/data/lrgb.py b/python/dgl/data/lrgb.py index 5290eb0517ec..17322c6ad441 100644 --- a/python/dgl/data/lrgb.py +++ b/python/dgl/data/lrgb.py @@ -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 diff --git a/python/dgl/data/superpixel.py b/python/dgl/data/superpixel.py index 9c1335153f06..41b3330f9023 100644 --- a/python/dgl/data/superpixel.py +++ b/python/dgl/data/superpixel.py @@ -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 diff --git a/python/dgl/data/utils.py b/python/dgl/data/utils.py index a63ee8471466..0719b97cabc2 100644 --- a/python/dgl/data/utils.py +++ b/python/dgl/data/utils.py @@ -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 diff --git a/python/dgl/nn/pytorch/explain/gnnexplainer.py b/python/dgl/nn/pytorch/explain/gnnexplainer.py index 6fd57ec25a7d..e2bd18af7dd3 100644 --- a/python/dgl/nn/pytorch/explain/gnnexplainer.py +++ b/python/dgl/nn/pytorch/explain/gnnexplainer.py @@ -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 diff --git a/python/dgl/nn/pytorch/network_emb.py b/python/dgl/nn/pytorch/network_emb.py index 3fccfc292e23..c773ca3d44c3 100644 --- a/python/dgl/nn/pytorch/network_emb.py +++ b/python/dgl/nn/pytorch/network_emb.py @@ -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 @@ -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 = [ diff --git a/script/dgl_dev.yml.template b/script/dgl_dev.yml.template index 0772f1daa7ce..28c5f50eef10 100644 --- a/script/dgl_dev.yml.template +++ b/script/dgl_dev.yml.template @@ -47,5 +47,7 @@ dependencies: - clang-format - pylint - lintrunner + - jupyterlab + - ipywidgets variables: DGL_HOME: __DGL_HOME__ diff --git a/tutorials/models/4_old_wines/7_transformer.py b/tutorials/models/4_old_wines/7_transformer.py index f489a750bb48..f196cd13dd69 100644 --- a/tutorials/models/4_old_wines/7_transformer.py +++ b/tutorials/models/4_old_wines/7_transformer.py @@ -589,7 +589,7 @@ # # .. code:: python # -# from tqdm import tqdm +# from tqdm.auto import tqdm # import torch as th # import numpy as np # diff --git a/tutorials/multi/2_node_classification.py b/tutorials/multi/2_node_classification.py index 9868b5f6567c..b31bb1674111 100644 --- a/tutorials/multi/2_node_classification.py +++ b/tutorials/multi/2_node_classification.py @@ -20,7 +20,6 @@ """ - ###################################################################### # Importing Packages # --------------- @@ -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 ###################################################################### @@ -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) @@ -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"]