internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: dmlc/dgl

Issue:
MultiLayerNeighborSampler related typos in the document
## 📚 Documentation

It seems MultiLayerNeighborSampler is deprecated/removed in doc and replaced by NeighborSampler.

Within the code example for NodeCollator class definition (https://docs.dgl.ai/en/rying_test/api/python/dgl.dataloading.html#collators), it states: 
_To train a 3-layer GNN for node classification on a set of nodes train_nid on a homogeneous graph where each node takes messages from **all neighbors** (assume the backend is PyTorch):_

However, here is the corresponding code snippet: 
```
sampler = dgl.dataloading.MultiLayerNeighborSampler([15, 10, 5])
collator = dgl.dataloading.NodeCollator(g, train_nid, sampler)
dataloader = torch.utils.data.DataLoader(
    collator.dataset, collate_fn=collator.collate,
    batch_size=1024, shuffle=True, drop_last=False, num_workers=4)
for input_nodes, output_nodes, blocks in dataloader:
    train_on(input_nodes, output_nodes, blocks)
```

Apparently, the example code is inconsistent with the statement, i.e., it is sampled with fanout [15,10,5], not full neighbor sampling.

Also, the example code for Dataloader definition at: https://docs.dgl.ai/generated/dgl.dataloading.DataLoader.html, has the same typo...



Discussion:

Resolving patch:
diff --git a/python/dgl/dataloading/dataloader.py b/python/dgl/dataloading/dataloader.py
--- a/python/dgl/dataloading/dataloader.py
+++ b/python/dgl/dataloading/dataloader.py
@@ -631,7 +631,8 @@ class DataLoader(torch.utils.data.DataLoader):
     Examples
     --------
     To train a 3-layer GNN for node classification on a set of nodes ``train_nid`` on
-    a homogeneous graph where each node takes messages from all neighbors (assume
+    a homogeneous graph where each node takes messages from 15 neighbors on the
+    first layer, 10 neighbors on the second, and 5 neighbors on the third (assume
     the backend is PyTorch):
 
     >>> sampler = dgl.dataloading.MultiLayerNeighborSampler([15, 10, 5])


Test patch:
Repository: dmlc/dgl

Issue:
[Example][Bug] Running error on the example case: example/pytorch/dimenet
## 🐛 Bug

Dimenet example is crashed. 

## To Reproduce

`python main.py --model-cnf config/dimenet.yaml`

```
Traceback (most recent call last):
  File "main.py", line 254, in <module>
    main()
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "main.py", line 165, in main
    model = DimeNet(emb_size=model_params['emb_size'],
  File "/workspace/examples/dimenet/modules/dimenet.py", line 64, in __init__
    self.rbf_layer = BesselBasisLayer(num_radial=num_radial,
  File "/workspace/examples/dimenet/modules/bessel_basis_layer.py", line 17, in __init__
    self.reset_params()
  File "/workspace/examples/dimenet/modules/bessel_basis_layer.py", line 20, in reset_params
    torch.arange(1, self.frequencies.numel() + 1, out=self.frequencies).mul_(np.pi)
RuntimeError: a leaf Variable that requires grad is being used in an in-place operation.
```

## Expected behavior

The case should run through

## Environment

 - DGL Version (e.g., 1.0): 0.9
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): 1.12
 - OS (e.g., Linux): ubuntu
 - How you installed DGL (`conda`, `pip`, source): source
 - Build command you used (if compiling from source):
 - Python version: 3.8
 - CUDA/cuDNN version (if applicable): 11.7
 - GPU models and configuration (e.g. V100): A100
 - Any other relevant information:




Discussion:

Resolving patch:
diff --git a/examples/pytorch/dimenet/modules/bessel_basis_layer.py b/examples/pytorch/dimenet/modules/bessel_basis_layer.py
--- a/examples/pytorch/dimenet/modules/bessel_basis_layer.py
+++ b/examples/pytorch/dimenet/modules/bessel_basis_layer.py
@@ -17,7 +17,9 @@ def __init__(self,
         self.reset_params()
 
     def reset_params(self):
-        torch.arange(1, self.frequencies.numel() + 1, out=self.frequencies).mul_(np.pi)
+        with torch.no_grad():
+            torch.arange(1, self.frequencies.numel() + 1, out=self.frequencies).mul_(np.pi)
+        self.frequencies.requires_grad_()
 
     def forward(self, g):
         d_scaled = g.edata['d'] / self.cutoff
@@ -25,4 +27,4 @@ def forward(self, g):
         d_scaled = torch.unsqueeze(d_scaled, -1)
         d_cutoff = self.envelope(d_scaled)
         g.edata['rbf'] = d_cutoff * torch.sin(self.frequencies * d_scaled)
-        return g
\ No newline at end of file
+        return g


Test patch:
Repository: dmlc/dgl

Issue:
[Dist] `get_partition_ids()` in dist partition pipeline returns unexpected values
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->
Report this on behalf of @Kh4L 

Traceback (most recent call last):
  File "/shared_workspace/mag240m/distpartitioning/data_proc_pipeline.py", line 68, in <module>
    multi_machine_run(params)
  File "/shared_workspace/mag240m/distpartitioning/data_shuffle.py", line 799, in multi_machine_run
    gen_dist_partitions(rank, params.world_size, params)
  File "/shared_workspace/mag240m/distpartitioning/data_shuffle.py", line 618, in gen_dist_partitions
    exchange_graph_data(rank, world_size, node_features, edge_features, \
  File "/shared_workspace/mag240m/distpartitioning/data_shuffle.py", line 385, in exchange_graph_data
    rcvd_node_features, rcvd_global_nids = exchange_features(rank, world_size, node_feat_tids,
  File "/shared_workspace/mag240m/distpartitioning/data_shuffle.py", line 275, in exchange_features
    partid_slice = id_lookup.get_partition_ids(np.arange(gnid_start, gnid_end, dtype=np.int64))
  File "/shared_workspace/mag240m/distpartitioning/dist_lookup.py", line 197, in get_partition_ids
    if len(global_type_nids) <= 0:
TypeError: object of type 'numpy.int64' has no len()

## To Reproduce

Steps to reproduce the behavior:

1. follow the tutorial: https://docs.dgl.ai/en/0.9.x/guide/distributed-preprocessing.html

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - DGL Version (e.g., 1.0): master
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3):
 - OS (e.g., Linux):
 - How you installed DGL (`conda`, `pip`, source):
 - Build command you used (if compiling from source):
 - Python version:
 - CUDA/cuDNN version (if applicable):
 - GPU models and configuration (e.g. V100):
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->



Discussion:
Thanks @Kh4L has already figured out the root cause: a typo causes this error. He will make a fix with complete test covered soon.
https://github.com/dmlc/dgl/blob/c235d17d2d01c54de243e479d213919e9a85264c/tools/distpartitioning/dist_lookup.py#L184

Resolving patch:
diff --git a/tools/distpartitioning/dist_lookup.py b/tools/distpartitioning/dist_lookup.py
--- a/tools/distpartitioning/dist_lookup.py
+++ b/tools/distpartitioning/dist_lookup.py
@@ -167,7 +167,7 @@ def get_partition_ids(self, global_nids):
                 continue
             # Get the node_type_ids and per_type_nids for the incoming global_nids.
             ntype_ids, type_nids = self.id_map(owner_req_list[idx].numpy())
-            nypte_ids, type_nids = ntype_ids.numpy(), type_nids.numpy()
+            ntype_ids, type_nids = ntype_ids.numpy(), type_nids.numpy()
 
             # Lists to store partition-ids for the incoming global-nids.
             type_id_lookups = []


Test patch:
Repository: dmlc/dgl

Issue:
[Sparse] Create a mock implementation in mock_sparse for BSDDMM.
## 🔨Work Item

**IMPORTANT:**
* This template is only for dev team to track project progress. For feature request or bug report, please use the corresponding issue templates.
* DO NOT create a new work item if the purpose is to fix an existing issue or feature request. We will directly use the issue in the project tracker.

Project tracker: https://github.com/orgs/dmlc/projects/2

## Description

<!-- short description of the work item -->

## Depending work items or issues

<!-- what must be done before this -->



Discussion:

Resolving patch:
diff --git a/python/dgl/mock_sparse/sddmm.py b/python/dgl/mock_sparse/sddmm.py
--- a/python/dgl/mock_sparse/sddmm.py
+++ b/python/dgl/mock_sparse/sddmm.py
@@ -1,9 +1,9 @@
 """Sampled Dense-Dense Matrix Multiplication (SDDMM) operator module."""
 import torch
 
-from .sp_matrix import SparseMatrix
+from .sp_matrix import create_from_coo, SparseMatrix
 
-__all__ = ["sddmm"]
+__all__ = ["sddmm", "mock_bsddmm"]
 
 
 def sddmm(
@@ -56,3 +56,56 @@ def sddmm(
     # PyTorch's sddmm operator only supports CSR format.
     res = torch.sparse.sampled_addmm(A.adj.to_sparse_csr(), mat1, mat2)
     return SparseMatrix(A.row, A.col, res.values(), A.adj.shape)
+
+
+def mock_bsddmm(
+    A: SparseMatrix, mat1: torch.Tensor, mat2: torch.Tensor
+) -> SparseMatrix:
+    r"""Batched Sampled-Dense-Dense Matrix Multiplication (SDDMM).
+
+    ``bsddmm`` conducts `sddmm` for each batch of the two dense matrices
+    independently.
+
+    In particular, :attr:``mat1`` and :attr:``mat2`` can be 2-D, which will be
+    reshape as `(B, M, 1)` and `(B, 1, K)` in the computation.
+
+    Parameters
+    ----------
+    A : SparseMatrix
+        Sparse matrix of shape `(M, N)`.
+    mat1 : Tensor
+        Dense matrix of shape `(B, M, K)` or `(B, M,)`
+    mat2 : Tensor
+        Dense matrix of shape `(B, K, N)` or `(B, K,)`
+
+    Returns
+    -------
+    SparseMatrix
+        Sparse matrix of shape `(M, N)` with non-zero values of `B` dimension.
+
+    Examples
+    --------
+
+    >>> row = torch.tensor([1, 1, 2])
+    >>> col = torch.tensor([2, 3, 3])
+    >>> val = torch.arange(1, 4).float()
+    >>> A = create_from_coo(row, col, val, (3, 4))
+    >>> mat1 = torch.randn(2, 3, 5)
+    >>> mat2 = torch.randn(2, 5, 4)
+    >>> dgl.mock_sparse.mock_bsddmm(A, mat1, mat2)
+    SparseMatrix(indices=tensor([[1, 1, 2],
+            [2, 3, 3]]),
+    values=tensor([[-0.6765, -0.4017],
+            [ 3.3290,  6.9016],
+            [ 4.8184,  5.8882]]),
+    shape=(3, 4), nnz=3)
+    """
+    batch_mat1 = [mat1[i, ...] for i in range(mat1.shape[0])]
+    batch_mat2 = [mat2[i, ...] for i in range(mat2.shape[0])]
+    batch_ret = [sddmm(A, lhs, rhs) for lhs, rhs in zip(batch_mat1, batch_mat2)]
+    return create_from_coo(
+        row=A.row,
+        col=A.col,
+        val=torch.stack([sp_mat.val for sp_mat in batch_ret], dim=-1),
+        shape=A.shape,
+    )


Test patch:
Repository: dmlc/dgl

Issue:
[Bug][Performance] Significant overhead when `record_stream` for subgraph in dataloading
## 🐛 Bug

It seems there are many overheads observed in dataloader during feature prefetching when `use_alternate_streams=True` . When it calls `_record_stream` for every subgraph (batch), like the following: 
https://github.com/dmlc/dgl/blob/829ce109f1604ee59ac039331a3609896301e8de/python/dgl/dataloading/dataloader.py#L339
many unnecessary h2d copies (or gpu feature slicing if use_uva) are invoked from L339, due to materializing the column data(feature) within its `record_stream` method, i.e., within its `data` method, for example from here (when uva is disabled)
https://github.com/dmlc/dgl/blob/829ce109f1604ee59ac039331a3609896301e8de/python/dgl/frame.py#L246-L251
called by `record_stream` method for each column:
https://github.com/dmlc/dgl/blob/829ce109f1604ee59ac039331a3609896301e8de/python/dgl/frame.py#L551

It poses significant slow-down for both cases: `use_uva=True` and `use_uva=False`, for example, when running `example/graphsage/node_classification.py`, with uva on, `use_alternate_streams=True` causes **1.56x** more time for each epoch, while with uva off, `use_alternate_streams=True` (default) causes **1.55x** more time for each epoch.


## To Reproduce

set `use_alternate_streams=True` and run

```
python node_classification.py
```

## Environment

 - DGL Version (e.g., 1.0): 1.0
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): Pytorch 1.13
 - How you installed DGL (`conda`, `pip`, source): source
 - GPU models and configuration (e.g. V100): A5000




Discussion:

Resolving patch:
diff --git a/python/dgl/frame.py b/python/dgl/frame.py
--- a/python/dgl/frame.py
+++ b/python/dgl/frame.py
@@ -5,7 +5,7 @@
 from collections.abc import MutableMapping
 
 from . import backend as F
-from .base import DGLError, dgl_warning
+from .base import dgl_warning, DGLError
 from .init import zero_initializer
 from .storages import TensorStorage
 from .utils import gather_pinned_tensor_rows, pin_memory_inplace
@@ -41,6 +41,17 @@ def flatten(self):
             flat_index = F.gather_row(flat_index, index)
         return flat_index
 
+    def record_stream(self, stream):
+        """Record stream for index.
+
+        Parameters
+        ----------
+        stream : torch.cuda.Stream.
+        """
+        for index in self._indices:
+            if F.context(index) != F.cpu():
+                index.record_stream(stream)
+
 
 class LazyFeature(object):
     """Placeholder for feature prefetching.
@@ -548,7 +559,13 @@ def record_stream(self, stream):
         """
         if F.get_preferred_backend() != "pytorch":
             raise DGLError("record_stream only supports the PyTorch backend.")
-        self.data.record_stream(stream)
+        if self.index is not None and (
+            isinstance(self.index, _LazyIndex)
+            or F.context(self.index) != F.cpu()
+        ):
+            self.index.record_stream(stream)
+        if F.context(self.storage) != F.cpu():
+            self.storage.record_stream(stream)
 
 
 class Frame(MutableMapping):


Test patch:
Repository: dmlc/dgl

Issue:
[Bug] An useless assignment in `GCN2Conv`
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

https://github.com/dmlc/dgl/blob/e178158616012f2e3bc83e28457127ce6dc0cf03/python/dgl/nn/pytorch/conv/gcn2conv.py#L258-L267

The assignment of Line 259 seems to be useless and thus can be replaced by

```python3
feat.add_(feat_0)
```

Or Line 260 mistyped `=` instead of `+=`?

## To Reproduce

Steps to reproduce the behavior:

1.
1.
1.

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - DGL Version (e.g., 1.0):
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3):
 - OS (e.g., Linux):
 - How you installed DGL (`conda`, `pip`, source):
 - Build command you used (if compiling from source):
 - Python version:
 - CUDA/cuDNN version (if applicable):
 - GPU models and configuration (e.g. V100):
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->



Discussion:
@kyawlin the original contributor of this module. This indeed looks strange to me because `add_` is an inplace operation which should be avoided usually to prevent breaking autograd.

Also cc the reviewer @BarclayII 
Hello, it seems this issue remains unresolved for a week. Is there someone WIP?

Resolving patch:
diff --git a/python/dgl/nn/pytorch/conv/gcn2conv.py b/python/dgl/nn/pytorch/conv/gcn2conv.py
--- a/python/dgl/nn/pytorch/conv/gcn2conv.py
+++ b/python/dgl/nn/pytorch/conv/gcn2conv.py
@@ -256,29 +256,12 @@ def forward(self, graph, feat, feat_0, edge_weight=None):
             feat_0 = feat_0[: feat.size(0)] * self.alpha
 
             if self._project_initial_features:
-                rst = feat.add_(feat_0)
-                rst = th.addmm(
-                    feat,
-                    feat,
-                    self.weight1,
-                    beta=(1 - self.beta),
-                    alpha=self.beta,
-                )
+                feat_sum = feat + feat_0
+                rst = (1 - self.beta) * feat_sum + self.beta * feat_sum @ self.weight1
             else:
-                rst = th.addmm(
-                    feat,
-                    feat,
-                    self.weight1,
-                    beta=(1 - self.beta),
-                    alpha=self.beta,
-                )
-                rst += th.addmm(
-                    feat_0,
-                    feat_0,
-                    self.weight2,
-                    beta=(1 - self.beta),
-                    alpha=self.beta,
-                )
+                feat_sum = feat + feat_0
+                feat_proj_sum = feat @ self.weight1 + feat_0 @ self.weight2
+                rst = (1 - self.beta) * feat_sum + self.beta * feat_proj_sum
 
             if self._bias:
                 rst = rst + self.bias


Test patch:
Repository: dmlc/dgl

Issue:
dgl/examples/multigpu /node_classification_sage.py does not work with OGB Papers100M dataset
## 🐛 Bug

<!-- The example in the DGL does not work with an OGB Papers100M dataset. -->

When run the example script `dgl/examples/multigpu /node_classification_sage.py` with papers 100M dataset, it throws the following error.
```
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/torch/multiprocessing/spawn.py", line 74, in _wrap
    fn(i, *args)
  File "/opt/dgl/dgl-source/examples/multigpu/node_classification_sage.py", line 279, in run
    train(
  File "/opt/dgl/dgl-source/examples/multigpu/node_classification_sage.py", line 209, in train
    loss = F.cross_entropy(y_hat, y)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/functional.py", line 3055, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Float'
```
## Environment

 - DGL Version (e.g., 1.1.1): 1.2
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): PyTorch 2.1.0
 - OS (e.g., Linux): Linux
 - How you installed DGL (`conda`, `pip`, source): source
 - Build command you used (if compiling from source):
 - Python version: 3.9
 - CUDA/cuDNN version (if applicable): CUDA 12.2.1 and cuDNN 8.9.5
 - GPU models and configuration (e.g. V100): V100
 - Any other relevant information: Can be reproduced by using NGC DGL container 23.07

## Additional context
It works by changing the line 207 from `y = blocks[-1].dstdata["label"]` to `y = blocks[-1].dstdata["label"].to(torch.int64)`


Discussion:

Resolving patch:
diff --git a/examples/multigpu/node_classification_sage.py b/examples/multigpu/node_classification_sage.py
--- a/examples/multigpu/node_classification_sage.py
+++ b/examples/multigpu/node_classification_sage.py
@@ -204,7 +204,7 @@ def train(
             train_dataloader
         ):
             x = blocks[0].srcdata["feat"]
-            y = blocks[-1].dstdata["label"]
+            y = blocks[-1].dstdata["label"].to(torch.int64)
             y_hat = model(blocks, x)
             loss = F.cross_entropy(y_hat, y)
             opt.zero_grad()


Test patch:
Repository: dmlc/dgl

Issue:
[GraphBolt][CUDA] Showcase `GPUCachedFeature` usage in an example.



Discussion:
@frozenbugs Do you think anybody would like to work on adding such an example? We could showcase it after a larger dataset is added to GraphBolt in as part of #6909. We can then showcase the speedups hopefully, however, to show speedups, the feature copy needs to dominate the overall training runtime. But with #6954, the feature copy can be fully overlapped so it is going to be a bit harder to show speedups after it is merged.

When we have a large dataset such as `ogbn-papers100M` or maybe the mag240M `hetero-rgcn.py` example, we need to wrap its main TorchBasedFeature with a GPUCachedFeature in #6939.

Resolving patch:
diff --git a/examples/multigpu/graphbolt/node_classification.py b/examples/multigpu/graphbolt/node_classification.py
--- a/examples/multigpu/graphbolt/node_classification.py
+++ b/examples/multigpu/graphbolt/node_classification.py
@@ -284,6 +284,12 @@ def run(rank, world_size, args, devices, dataset):
     hidden_size = 256
     out_size = num_classes
 
+    if args.gpu_cache_size > 0:
+        dataset.feature._features[("node", None, "feat")] = gb.GPUCachedFeature(
+            dataset.feature._features[("node", None, "feat")],
+            args.gpu_cache_size,
+        )
+
     # Create GraphSAGE model. It should be copied onto a GPU as a replica.
     model = SAGE(in_size, hidden_size, out_size).to(device)
     model = DDP(model)
@@ -381,6 +387,12 @@ def parse_args():
     parser.add_argument(
         "--num-workers", type=int, default=0, help="The number of processes."
     )
+    parser.add_argument(
+        "--gpu-cache-size",
+        type=int,
+        default=0,
+        help="The GPU cache size for input features.",
+    )
     parser.add_argument(
         "--mode",
         default="pinned-cuda",


Test patch:
Repository: wevote/WeVoteServer

Issue:
Organization view: Summarize number of positions
User request: In the Organization admin view, show the total number of positions taken.

![4ff25d7954e19214881c7fcaaadf2dbc _image 202017-08-31 20at 205 36 16 20pm public](https://user-images.githubusercontent.com/149811/29984727-9cdba806-8f29-11e7-8e9b-bfa608601d80.png)

This helps with manual data entry: As the user is entering positions, she can quickly see whether she's entered all of them.


Discussion:

Resolving patch:
diff --git a/organization/views_admin.py b/organization/views_admin.py
--- a/organization/views_admin.py
+++ b/organization/views_admin.py
@@ -568,6 +568,7 @@ def organization_position_list_view(request, organization_id):
                 'messages_on_stage':            messages_on_stage,
                 'organization':                 organization_on_stage,
                 'organization_position_list':   organization_position_list,
+                'organization_num_positions':   len(organization_position_list),
                 'election_list':                election_list,
                 'google_civic_election_id':     google_civic_election_id,
                 'candidate_we_vote_id':         candidate_we_vote_id,
@@ -689,6 +690,7 @@ def organization_position_new_view(request, organization_id):
             'google_civic_election_id':                     google_civic_election_id,
             'state_code':                                   state_code,
             'organization_position_list':                   organization_position_list,
+            'organization_num_positions':                   len(organization_position_list),
             'voter_authority':                              authority_results,
             # Incoming values from error state
             'candidate_and_measure_not_found':              candidate_and_measure_not_found,


Test patch: