internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: weni-ai/bothub-engine

Issue:
Updating settings and remove sentences, training keeps enabled
Reported by @johncordeiro in https://github.com/Ilhasoft/bothub/issues/44


Discussion:

Resolving patch:
diff --git a/bothub/common/models.py b/bothub/common/models.py
--- a/bothub/common/models.py
+++ b/bothub/common/models.py
@@ -460,6 +460,9 @@ def ready_for_train(self):
         if self.training_started_at:
             return False
 
+        if len(self.requirements_to_train) > 0:
+            return False
+
         previous_update = self.repository.updates.filter(
             language=self.language,
             by__isnull=False,


Test patch:
diff --git a/bothub/common/tests.py b/bothub/common/tests.py
--- a/bothub/common/tests.py
+++ b/bothub/common/tests.py
@@ -767,7 +767,8 @@ def setUp(self):
             owner=self.owner,
             name='Test',
             slug='test',
-            language=languages.LANGUAGE_EN)
+            language=languages.LANGUAGE_EN,
+            use_language_model_featurizer=False)
 
     def test_be_true(self):
         RepositoryExample.objects.create(
@@ -871,6 +872,19 @@ def test_entity_dont_have_min_examples(self):
             entity='hi')
         self.assertTrue(self.repository.current_update().ready_for_train)
 
+    def test_settings_change_exists_requirements(self):
+        self.repository.current_update().start_training(self.owner)
+        self.repository.use_language_model_featurizer = True
+        self.repository.save()
+        RepositoryExample.objects.create(
+            repository_update=self.repository.current_update(),
+            text='hello',
+            intent='greet')
+        self.assertEqual(
+            len(self.repository.current_update().requirements_to_train),
+            1)
+        self.assertFalse(self.repository.current_update().ready_for_train)
+
     def test_no_examples(self):
         example = RepositoryExample.objects.create(
             repository_update=self.repository.current_update(),
Repository: weni-ai/bothub-engine

Issue:
Updates incorrect order
<img width="1060" alt="screen shot 2018-10-10 at 10 44 30 am" src="https://user-images.githubusercontent.com/8301135/46740768-fcd92b00-cc79-11e8-9d12-c19a2feb7768.png">



Discussion:

Resolving patch:
diff --git a/bothub/api/v1/views.py b/bothub/api/v1/views.py
--- a/bothub/api/v1/views.py
+++ b/bothub/api/v1/views.py
@@ -989,7 +989,7 @@ class RepositoryUpdatesViewSet(
       mixins.ListModelMixin,
       GenericViewSet):
     queryset = RepositoryUpdate.objects.filter(
-        training_started_at__isnull=False)
+        training_started_at__isnull=False).order_by('-trained_at')
     serializer_class = RepositoryUpdateSerializer
     filter_class = RepositoryUpdatesFilter
     permission_classes = [


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
PointCNN dilated KNN might select less than `K` neighbours 
## 🐛 Bug

In the current X-Conv implementation, I can see the following:

https://github.com/rusty1s/pytorch_geometric/blob/e8e004439e3204a7b888a21e508c45d166c5817c/torch_geometric/nn/conv/x_conv.py#L130-L137

As, `torch.randint` would sample with replacement, there's a chance that the number of actual neighbours can be less than `K`. I am thinking we can fix this using something like:

```
indices = torch.randperm(K * dil)[:K]
```


Discussion:
Yes, I think it makes sense to fix this, e.g., the official implementation just takes each `D`-th entry. Are you interested in fixing this?
Yup. PR on the way. 

Resolving patch:
diff --git a/torch_geometric/nn/conv/x_conv.py b/torch_geometric/nn/conv/x_conv.py
--- a/torch_geometric/nn/conv/x_conv.py
+++ b/torch_geometric/nn/conv/x_conv.py
@@ -125,16 +125,11 @@ def forward(self, x: Tensor, pos: Tensor, batch: Optional[Tensor] = None):
         edge_index = knn_graph(pos, K * self.dilation, batch, loop=True,
                                flow='target_to_source',
                                num_workers=self.num_workers)
-        row, col = edge_index[0], edge_index[1]
 
         if self.dilation > 1:
-            dil = self.dilation
-            index = torch.randint(K * dil, (N, K), dtype=torch.long,
-                                  device=row.device)
-            arange = torch.arange(N, dtype=torch.long, device=row.device)
-            arange = arange * (K * dil)
-            index = (index + arange.view(-1, 1)).view(-1)
-            row, col = row[index], col[index]
+            edge_index = edge_index[:, ::K]
+
+        row, col = edge_index[0], edge_index[1]
 
         pos = pos[col] - pos[row]
 


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
Computing the size of the in-degree histogram tensor dynamically in the PNA example
### 🛠 Proposed Refactor

The `deg` tensor in the PNA example is initialized with the size `5`. 
https://github.com/pyg-team/pytorch_geometric/blob/50b7bfc4a59b5b6f7ec547ff862985f3b2e22798/examples/pna.py#L23

This value will obviously be different for different datasets. One can iterate over the training data and compute the maximum degree any node has. Then, the histogram tensor can be initialized with that value. Something like this:
```python
# compute the maximum in-degree in the training data
max_degree = 0
for data in train_dataset:
    d = degree(data.edge_index[1], num_nodes=data.num_nodes, dtype=torch.long)
    if d.max().item() > max_degree:
        max_degree = d.max().item()

# create the in-degree histogram tensor
deg = torch.zeros(max_degree + 1, dtype=torch.long)
for data in train_dataset:
    d = degree(data.edge_index[1], num_nodes=data.num_nodes, dtype=torch.long)
    deg += torch.bincount(d, minlength=deg.numel())
``` 

### Suggest a potential alternative/fix

The results of the `degree` function can also be cached to avoid iterating two times. Further, for custom datasets where the split is made with indices or boolean masks e.g `Data(x=[10000, 100], edge_index=[2, 200000], edge_attr=[200000, 20], y=[10000], train_mask=[10000], val_mask=[10000], test_mask=[10000])`, the `subgraph` utility can be used.
```python
tr_subgraph = data.subgraph(data.train_mask)
# compute the in-degree of all the training nodes
d = degree(index=tr_subgraph.edge_index[1], num_nodes=tr_subgraph.num_nodes, dtype=torch.long)

# get the maximum in-degree, this will be the size of the histogram tensor
max_degree = d.max().item()

# create the in-degree histogram tensor
deg = torch.zeros(max_degree + 1, dtype=torch.long)
deg += torch.bincount(d, minlength=deg.numel())
```


Discussion:
That is a good change, as it allows to apply `PNA` more easily to other datasets as well. Please go ahead and contribute this feature :)

Resolving patch:
diff --git a/examples/pna.py b/examples/pna.py
--- a/examples/pna.py
+++ b/examples/pna.py
@@ -19,8 +19,14 @@
 val_loader = DataLoader(val_dataset, batch_size=128)
 test_loader = DataLoader(test_dataset, batch_size=128)
 
-# Compute in-degree histogram over training data.
-deg = torch.zeros(5, dtype=torch.long)
+# Compute the maximum in-degree in the training data.
+max_degree = -1
+for data in train_dataset:
+    d = degree(data.edge_index[1], num_nodes=data.num_nodes, dtype=torch.long)
+    max_degree = max(max_degree, int(d.max()))
+
+# Compute the in-degree histogram tensor
+deg = torch.zeros(max_degree + 1, dtype=torch.long)
 for data in train_dataset:
     d = degree(data.edge_index[1], num_nodes=data.num_nodes, dtype=torch.long)
     deg += torch.bincount(d, minlength=deg.numel())


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
NELL dataset doesn't have num_features and num_node_features
### 🐛 Describe the bug

num_features and num_node_features are 0 for NELL dataset. I'm not familiar with PyG dataset internals, but I suspect it is due to node features in NELL is a `SparseTensor` instance instead of a normal `Tensor`.

```python
from torch_geometric.datasets import NELL

ds = NELL("data")
print(ds.num_node_features)  # 0
print(ds.num_features)       # 0
```

### Environment

* PyG version: 2.0.4
* PyTorch version: 1.11.0
* OS: macOS Monterey 12.4
* Python version: 3.10.5
* CUDA/cuDNN version: NA
* How you installed PyTorch and PyG (`conda`, `pip`, source): PyTorch through conda, PyG through pip
* Any other relevant information (*e.g.*, version of `torch-scatter`):



Discussion:
Thanks for reporting. Let me take a look.

Resolving patch:
diff --git a/torch_geometric/data/storage.py b/torch_geometric/data/storage.py
--- a/torch_geometric/data/storage.py
+++ b/torch_geometric/data/storage.py
@@ -288,7 +288,7 @@ def num_nodes(self) -> Optional[int]:
 
     @property
     def num_node_features(self) -> int:
-        if 'x' in self and isinstance(self.x, Tensor):
+        if 'x' in self and isinstance(self.x, (Tensor, SparseTensor)):
             return 1 if self.x.dim() == 1 else self.x.size(-1)
         return 0
 


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
The the feature dim of data.x is zero in Proteins dataset with the pyg version after 2.0.5
### 🐛 Describe the bug

The main reason is in line 136 of tu_dataset.py

it is strange that the value of num_edge_attributes is larger than the feature dimension of self.data.x in proteins, which leads to the resulting dimension of self.data.x is num_nodes*0


### Environment

* PyG version:
* PyTorch version:
* OS:
* Python version:
* CUDA/cuDNN version:
* How you installed PyTorch and PyG (`conda`, `pip`, source):
* Any other relevant information (*e.g.*, version of `torch-scatter`):



Discussion:
Second this, I just noticed the 3 atom types in `PROTEINS` are only added when setting `use_node_attr=True` in the constructor (but then we get an additional feature which was not there before). However this is not consistent with the behavior of other datasets like `NCI1`, where atom type is always present. This change of behavior can seriously impact the reproducibility of libraries using this dataset. Please fix it asap. 

Resolving patch:
diff --git a/torch_geometric/io/tu.py b/torch_geometric/io/tu.py
--- a/torch_geometric/io/tu.py
+++ b/torch_geometric/io/tu.py
@@ -27,6 +27,8 @@ def read_tu_data(folder, prefix):
     node_attributes = torch.empty((batch.size(0), 0))
     if 'node_attributes' in names:
         node_attributes = read_file(folder, prefix, 'node_attributes')
+        if node_attributes.dim() == 1:
+            node_attributes = node_attributes.unsqueeze(-1)
 
     node_labels = torch.empty((batch.size(0), 0))
     if 'node_labels' in names:
@@ -41,6 +43,8 @@ def read_tu_data(folder, prefix):
     edge_attributes = torch.empty((edge_index.size(1), 0))
     if 'edge_attributes' in names:
         edge_attributes = read_file(folder, prefix, 'edge_attributes')
+        if edge_attributes.dim() == 1:
+            edge_attributes = edge_attributes.unsqueeze(-1)
 
     edge_labels = torch.empty((edge_index.size(1), 0))
     if 'edge_labels' in names:


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
Some layer parameters are not reset
### 🐛 Describe the bug

For the file: `torch_geometric/nn/models/dimenet.py`

In `reset_parameters()` of `InteractionPPBlock`, `self.layers_before_skip` is reset twice, and `self.layers_after_skip` is not reset at all.

This is the current version:

```python
for res_layer in self.layers_before_skip:
            res_layer.reset_parameters()
...
for res_layer in self.layers_before_skip:
    res_layer.reset_parameters()
```

But I think it should be:

```python
for res_layer in self.layers_before_skip:
            res_layer.reset_parameters()
...
for res_layer in self.layers_after_skip:
    res_layer.reset_parameters()
```

This second (fixed) version is consistent with the rest of the classes in this file.

### Environment

* PyG version:
* PyTorch version:
* OS:
* Python version:
* CUDA/cuDNN version:
* How you installed PyTorch and PyG (`conda`, `pip`, source):
* Any other relevant information (*e.g.*, version of `torch-scatter`):



Discussion:

Resolving patch:
diff --git a/torch_geometric/nn/models/dimenet.py b/torch_geometric/nn/models/dimenet.py
--- a/torch_geometric/nn/models/dimenet.py
+++ b/torch_geometric/nn/models/dimenet.py
@@ -275,7 +275,7 @@ def reset_parameters(self):
             res_layer.reset_parameters()
         glorot_orthogonal(self.lin.weight, scale=2.0)
         self.lin.bias.data.fill_(0)
-        for res_layer in self.layers_before_skip:
+        for res_layer in self.layers_after_skip:
             res_layer.reset_parameters()
 
     def forward(self, x: Tensor, rbf: Tensor, sbf: Tensor, idx_kj: Tensor,


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
`data.num_edges` is 0 when using native PyTorch sparse tensor
### 🐛 Describe the bug

When using the native PyTorch sparse tensor for representing the adjacency matrix, the number of edges reported by the `Data` object is always zero. The following code reproduces the issue:

```python
import torch_geometric.transforms as T
from torch_geometric.datasets import Planetoid

transform = T.ToSparseTensor(layout=torch.sparse_csr)
dataset = Planetoid("Planetoid", name="Cora", transform=transform)
data = dataset[0]
print(data.num_edges)
```

### Environment

* PyG version: 2.3.0
* PyTorch version: 2.0.0
* OS: Linux (Debian)
* Python version: 3.10.9



Discussion:

Resolving patch:
diff --git a/torch_geometric/data/storage.py b/torch_geometric/data/storage.py
--- a/torch_geometric/data/storage.py
+++ b/torch_geometric/data/storage.py
@@ -26,6 +26,7 @@
 from torch_geometric.utils import (
     coalesce,
     contains_isolated_nodes,
+    is_torch_sparse_tensor,
     is_undirected,
 )
 
@@ -418,6 +419,8 @@ def num_edges(self) -> int:
         for value in self.values('adj', 'adj_t'):
             if isinstance(value, SparseTensor):
                 return value.nnz()
+            elif is_torch_sparse_tensor(value):
+                return value._nnz()
         return 0
 
     @property


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
IndexError when using dimnet plus plus with pretrained on qm9 dataset (just running the example provided by PYG)
### 🐛 Describe the bug

I was trying to run the example provided by PYG using dimnet plus plus pretrained on qm9 dataset, the lik for the example: https://github.com/pyg-team/pytorch_geometric/blob/master/examples/qm9_pretrained_dimenet.py

I didn't change anything in the code, yet it gave me this error:
IndexError: Only slices (':'), list, tuples, torch.tensor and np.ndarray of dtype long or bool are valid indices (got 'Tensor')


### Environment

* PyG version: 2.3.0
* PyTorch version: 2.0.0+cpu
* OS: Windows-10-10.0.19045-SP0
* Python version: 3.10
* CUDA/cuDNN version: N/A
* How you installed PyTorch and PyG (`conda`, `pip`, source): pip
* Any other relevant information (*e.g.*, version of `torch-scatter`):



Discussion:
Thanks for reporting. @wsad1 do you mind to take a look?
@rusty1s @AmgadAbdallah This is because `perm` is a `torch.int32` Tensor but only `torch.int64` is supported for `torch_geometric.data.Dataset`. A quick fix is to convert `perm` to `torch.int64` Tensor.

https://github.com/pyg-team/pytorch_geometric/blob/3c1501833b13cb87e110a89edef5aa6ee164c190/torch_geometric/nn/models/dimenet.py#L633-L638

Resolving patch:
diff --git a/torch_geometric/nn/models/dimenet.py b/torch_geometric/nn/models/dimenet.py
--- a/torch_geometric/nn/models/dimenet.py
+++ b/torch_geometric/nn/models/dimenet.py
@@ -631,6 +631,7 @@ def copy_(src, name, transpose=False):
         # Use the same random seed as the official DimeNet` implementation.
         random_state = np.random.RandomState(seed=42)
         perm = torch.from_numpy(random_state.permutation(np.arange(130831)))
+        perm = perm.long()
         train_idx = perm[:110000]
         val_idx = perm[110000:120000]
         test_idx = perm[120000:]
@@ -905,6 +906,7 @@ def copy_(src, name, transpose=False):
 
         random_state = np.random.RandomState(seed=42)
         perm = torch.from_numpy(random_state.permutation(np.arange(130831)))
+        perm = perm.long()
         train_idx = perm[:110000]
         val_idx = perm[110000:120000]
         test_idx = perm[120000:]


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
Fail to import Nell dataset
### 🐛 Describe the bug

I tried to import Nell data set using NELL class:
from torch_geometric.datasets import NELL

dataset = NELL(root='data/Nell')
data = dataset[0]

But I got the following error message:
Traceback (most recent call last):
  File "c:\Users\13466\Desktop\USTLab\LabDoc\HPCA23\Nell.py", line 10, in <module>
    dataset = NELL(root='data/Nell')
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\datasets\nell.py", line 62, in __init__
    super().__init__(root, transform, pre_transform)
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\data\in_memory_dataset.py", line 57, in __init__
    super().__init__(root, transform, pre_transform, pre_filter, log)
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\data\dataset.py", line 97, in __init__
    self._process()
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\data\dataset.py", line 230, in _process
    self.process()
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\datasets\nell.py", line 82, in process
    data = read_planetoid_data(self.raw_dir, 'nell.0.001')
  File "C:\Users\13466\anaconda3\lib\site-packages\torch_geometric\io\planetoid.py", line 53, in read_planetoid_data
    row, col, value = SparseTensor.from_dense(x).coo()
AttributeError: type object 'SparseTensor' has no attribute 'from_dense'



### Environment

* PyG version:2.3.1
* PyTorch version:2.0.1
* OS:Windows 11
* Python version:3.10
* CUDA/cuDNN version:
* How you installed PyTorch and PyG (`conda`, `pip`, source):pip
* Any other relevant information (*e.g.*, version of `torch-scatter`):



Discussion:
You need to install `torch_sparse` to fix it.

Resolving patch:
diff --git a/torch_geometric/typing.py b/torch_geometric/typing.py
--- a/torch_geometric/typing.py
+++ b/torch_geometric/typing.py
@@ -105,6 +105,11 @@ def from_edge_index(
         ) -> 'SparseTensor':
             raise ImportError("'SparseTensor' requires 'torch-sparse'")
 
+        @classmethod
+        def from_dense(self, mat: Tensor,
+                       has_value: bool = True) -> 'SparseTensor':
+            raise ImportError("'SparseTensor' requires 'torch-sparse'")
+
         def size(self, dim: int) -> int:
             raise ImportError("'SparseTensor' requires 'torch-sparse'")
 


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
`CaptumExplainer` cannot be called multiple times in a row without creating an error
### 🐛 Describe the bug

Trying to call an instance of `CaptumExplainer` twice raises an error.


To replicate, change https://github.com/pyg-team/pytorch_geometric/blob/dfd32668aea953c8bb56f97364d8e028f267bde6/examples/explain/captum_explainer.py#L60

to 

```python
explanation = explainer(data.x, data.edge_index, index=node_index)
explanation_2 = explanation = explainer(data.x, data.edge_index, index=node_index+1)
```

which will raise

```
Traceback (most recent call last):
  File ".../pytorch_geometric/examples/explain/captum_explainer.py", line 62, in <module>
    explanation_2 = explainer(data.x, data.edge_index, index=11)
  File ".../pytorch_geometric/torch_geometric/explain/explainer.py", line 198, in __call__
    explanation = self.algorithm(
  File ".../pytorch_geometric/env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File ".../torch_geometric/explain/algorithm/captum_explainer.py", line 153, in forward
    self.attribution_method = self.attribution_method(captum_model)
TypeError: 'IntegratedGradients' object is not callable
```

This is because on the second call, the `CaptumExplainer` tries to recreates an attribution method from `captum`:

https://github.com/pyg-team/pytorch_geometric/blob/dfd32668aea953c8bb56f97364d8e028f267bde6/torch_geometric/explain/algorithm/captum_explainer.py#L153 


### Environment

* PyG version: (from source, latest commit to date on master)
* PyTorch version: 2.0.0


Discussion:

Resolving patch:
diff --git a/torch_geometric/explain/algorithm/captum_explainer.py b/torch_geometric/explain/algorithm/captum_explainer.py
--- a/torch_geometric/explain/algorithm/captum_explainer.py
+++ b/torch_geometric/explain/algorithm/captum_explainer.py
@@ -150,7 +150,7 @@ def forward(
             metadata = None
             captum_model = CaptumModel(model, mask_type, index)
 
-        self.attribution_method = self.attribution_method(captum_model)
+        attribution_method = self.attribution_method(captum_model)
 
         # In captum, the target is the index for which
         # the attribution is computed.
@@ -159,7 +159,7 @@ def forward(
         else:
             target = target[index]
 
-        attributions = self.attribution_method.attribute(
+        attributions = attribution_method.attribute(
             inputs=inputs,
             target=target,
             additional_forward_args=add_forward_args,


Test patch:
Repository: pyg-team/pytorch_geometric

Issue:
Planetoid dtype mismatch for CiteSeer
### 🐛 Describe the bug

I find that I can't load the CiteSeer dataset with double precision

```python
import torch_geometric as tg
tg.datasets.Planetoid(root="/tmp", name="CiteSeer")
```

I get this error

```
File /user/work/pc22286/mambaforge/envs/dkm/lib/python3.11/site-packages/torch_geometric/io/planetoid.py:34, in read_planetoid_data(folder, prefix)
     31 len_test_indices = (test_index.max() - test_index.min()).item() + 1
     33 tx_ext = torch.zeros(len_test_indices, tx.size(1))
---> 34 tx_ext[sorted_test_index - test_index.min(), :] = tx
     35 ty_ext = torch.zeros(len_test_indices, ty.size(1))
     36 ty_ext[sorted_test_index - test_index.min(), :] = ty

RuntimeError: Index put requires the source and destination dtypes match, got Double for the destination and Float for the source.
```

Fortunately, there is a workaround if I set the default precision to single precision

```python
import torch as t
t.set_default_dtype(t.float32)
tg.datasets.Planetoid(root="/tmp", name="CiteSeer") ## success, this time
```

and then I will convert to double precision manually later. Not a bit problem, but I expected to be able to use float64

### Environment

* PyG version: 2.3.1
* PyTorch version: 2.0.1
* OS: CentOS 7
* Python version: 3.11.3
* CUDA/cuDNN version: 12.0
* How you installed PyTorch and PyG (`conda`, `pip`, source): installed torch by conda (mamba), PyG by pip
* Any other relevant information (*e.g.*, version of `torch-scatter`):



Discussion:

Resolving patch:
diff --git a/torch_geometric/io/planetoid.py b/torch_geometric/io/planetoid.py
--- a/torch_geometric/io/planetoid.py
+++ b/torch_geometric/io/planetoid.py
@@ -30,9 +30,9 @@ def read_planetoid_data(folder, prefix):
         # as zero vectors to `tx` and `ty`.
         len_test_indices = (test_index.max() - test_index.min()).item() + 1
 
-        tx_ext = torch.zeros(len_test_indices, tx.size(1))
+        tx_ext = torch.zeros(len_test_indices, tx.size(1), dtype=tx.dtype)
         tx_ext[sorted_test_index - test_index.min(), :] = tx
-        ty_ext = torch.zeros(len_test_indices, ty.size(1))
+        ty_ext = torch.zeros(len_test_indices, ty.size(1), dtype=ty.dtype)
         ty_ext[sorted_test_index - test_index.min(), :] = ty
 
         tx, ty = tx_ext, ty_ext


Test patch: