internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: microsoft/torchgeo

Issue:
Checkpoint saving not working as expected
### Description

After migrating to release 0.5.0 noticed that checkpoint saving is not working as expected.

## description
tried different configuration e.g., `checkpoint_callback = ModelCheckpoint(monitor="val_loss", dirpath=ckpt_dir, save_last=True, every_n_epochs=1, save_top_k=1)` for example when running 20-30 epochs for training a model.
after training was completed could not find the ckpt file. what was found was a single ckpt file of the first epoch only, in a wrong directory.

## severance
the bug is very limiting. for example, after hours of training a model, there is no way to load the model from a checkpoint to run inference. the single shot to run inference was during the same run. 

## expected behavior
using a given configuration expected to see:
- checkpoint files saved every number of epoch
- the last epoch checkpoint file
- the checkpoints should have been saved to the given directory

## observed behavior
- after training several epochs only the first was saved.
- the single checkpoint were saved to another directory under the logger output

## initial investigation
1. checkpoint callback created and training fit called
2. later, see image and call stack:
seems like c'tor called again with save_last=None
![image](https://github.com/microsoft/torchgeo/assets/11072478/667b6cc1-8b7b-4ede-a61d-c365e851ab59)

3. when saving later supposed to happen, the save_last is None:
![image](https://github.com/microsoft/torchgeo/assets/11072478/2dd68eff-3c43-4ccc-8ce7-4a463044000b)

4. last checkpoint saving is skipped


### Steps to reproduce

1. create a checkpoint callback and use different checkpoints saving parameters e.g., checkpoint_callback = ModelCheckpoint(monitor="val_loss", dirpath=ckpt_dir, save_last=True, every_n_epochs=1, save_top_k=1)
2. call trainer fit and run several epochs
3. check expected results:
- saving location as expected e.g., under C:\foo 
- check last epoch checkpoint saved - must have last.ckpt
- check how many checkpoints were saved e.g., every 2 etc

### Version

torchgeo version 0.5.0, lightning version 2.0.9


Discussion:

Resolving patch:
diff --git a/torchgeo/trainers/base.py b/torchgeo/trainers/base.py
--- a/torchgeo/trainers/base.py
+++ b/torchgeo/trainers/base.py
@@ -8,7 +8,6 @@
 
 import lightning
 from lightning.pytorch import LightningModule
-from lightning.pytorch.callbacks import Callback, EarlyStopping, ModelCheckpoint
 from torch.optim import AdamW
 from torch.optim.lr_scheduler import ReduceLROnPlateau
 
@@ -36,17 +35,6 @@ def __init__(self) -> None:
         self.configure_metrics()
         self.configure_models()
 
-    def configure_callbacks(self) -> list[Callback]:
-        """Initialize model-specific callbacks.
-
-        Returns:
-            List of callbacks to apply.
-        """
-        return [
-            ModelCheckpoint(monitor=self.monitor, mode=self.mode),
-            EarlyStopping(monitor=self.monitor, mode=self.mode),
-        ]
-
     def configure_losses(self) -> None:
         """Initialize the loss criterion."""
 


Test patch:
Repository: microsoft/torchgeo

Issue:
ChesapeakeCVPR: use NLCD mapping/cmap
### Summary

We recently added a new NLCD dataset. Instead of duplicating the class mapping and cmap in ChesapeakeCVPR, we should use them from the NLCD dataset.

### Rationale

Code duplication is bad.

### Implementation

```python
from .nlcd import NLCD

cmap = NLCD.cmap
```

### Alternatives

Only reason to not duplicate them is in case we add Alaska to NLCD, which contains classes that don't exist in ChesapeakeCVPR. This doesn't affect cmap, but may affect the class mapping if we want to minimize the number of predicted classes.

### Additional information

_No response_


Discussion:
@calebrob6 are you able to work on this?

Resolving patch:
diff --git a/torchgeo/datasets/chesapeake.py b/torchgeo/datasets/chesapeake.py
--- a/torchgeo/datasets/chesapeake.py
+++ b/torchgeo/datasets/chesapeake.py
@@ -24,6 +24,7 @@
 from torch import Tensor
 
 from .geo import GeoDataset, RasterDataset
+from .nlcd import NLCD
 from .utils import BoundingBox, DatasetNotFoundError, download_url, extract_archive
 
 
@@ -439,26 +440,6 @@ class ChesapeakeCVPR(GeoDataset):
         15: (0, 0, 0, 0),
     }
 
-    nlcd_cmap = {
-        0: (0, 0, 0, 0),
-        11: (70, 107, 159, 255),
-        12: (209, 222, 248, 255),
-        21: (222, 197, 197, 255),
-        22: (217, 146, 130, 255),
-        23: (235, 0, 0, 255),
-        24: (171, 0, 0, 255),
-        31: (179, 172, 159, 255),
-        41: (104, 171, 95, 255),
-        42: (28, 95, 44, 255),
-        43: (181, 197, 143, 255),
-        52: (204, 184, 121, 255),
-        71: (223, 223, 194, 255),
-        81: (220, 217, 57, 255),
-        82: (171, 108, 40, 255),
-        90: (184, 217, 235, 255),
-        95: (108, 159, 184, 255),
-    }
-
     prior_color_matrix = np.array(
         [
             [0.0, 0.77254902, 1.0, 1.0],
@@ -574,8 +555,8 @@ def __init__(
         lc_colors = lc_colors[:, :3] / 255
         self._lc_cmap = ListedColormap(lc_colors)
 
-        nlcd_colors = np.zeros((max(self.nlcd_cmap.keys()) + 1, 4))
-        nlcd_colors[list(self.nlcd_cmap.keys())] = list(self.nlcd_cmap.values())
+        nlcd_colors = np.zeros((max(NLCD.cmap.keys()) + 1, 4))
+        nlcd_colors[list(NLCD.cmap.keys())] = list(NLCD.cmap.values())
         nlcd_colors = nlcd_colors[:, :3] / 255
         self._nlcd_cmap = ListedColormap(nlcd_colors)
 


Test patch:
Repository: microsoft/torchgeo

Issue:
SustainBenchCropYield download doesn't work
### Description

Downloading the SustainBenchCropYield dataset doesn't work as expected

### Steps to reproduce

```
ds = SustainBenchCropYield("data/", download=True)
```

This downloads a file called `soybeans` then fails unzipping `soybeans.zip`. Works if you rename to .zip and unzip manually.

### Version

0.6.0.dev0


Discussion:

Resolving patch:
diff --git a/torchgeo/datasets/sustainbench_crop_yield.py b/torchgeo/datasets/sustainbench_crop_yield.py
--- a/torchgeo/datasets/sustainbench_crop_yield.py
+++ b/torchgeo/datasets/sustainbench_crop_yield.py
@@ -211,7 +211,7 @@ def _download(self) -> None:
         download_url(
             self.url,
             self.root,
-            filename=self.dir,
+            filename=self.dir + ".zip",
             md5=self.md5 if self.checksum else None,
         )
         self._extract()


Test patch:
Repository: microsoft/torchgeo

Issue:
Add instructions on downloading the DeepGlobeLandCover dataset
### Issue

The [dataset](https://torchgeo.readthedocs.io/en/stable/api/datasets.html#torchgeo.datasets.DeepGlobeLandCover) docs state `The dataset that we use with a custom train/test split can be downloaded from Kaggle` - however this is a necessity as you cannot pass `download=True`

### Fix

Suggest documenting the steps using kaggle  CLI (below), or just to state that this must be performed? Alternatively host on Huggingface and automate the download

```
pip install kaggle # place api key at ~/.kaggle/kaggle.json
cd data
kaggle datasets download -d geoap96/deepglobe2018-landcover-segmentation-traindataset
unzip deepglobe2018-landcover-segmentation-traindataset.zip
```


Discussion:
> Alternatively host on Huggingface and automate the download

We haven't yet found the license for the dataset, so I'm not sure if we can do this. Want to try to reach out to the authors of the dataset to see? If the license permits redistribution, I'll add it to our Hugging Face account.
Reading the [paper](https://arxiv.org/pdf/1805.06561.pdf), appears the imagery is from deepglobe/maxar, will check my network for contacts there
Any updates on this?
RE license, I came to a dead end - the people I spoke to who had worked on the dataset have all moved on

As to updating the docs, I think it could be useful if you could clarify what level of detail we should be providing?
https://torchgeo.readthedocs.io/en/stable/api/datasets.html#torchgeo.datasets.SSL4EOS12 is an example of a similar dataset where users have to manually download it. So a similar level of detail is fine. Want to submit a PR?

Resolving patch:
diff --git a/torchgeo/datasets/deepglobelandcover.py b/torchgeo/datasets/deepglobelandcover.py
--- a/torchgeo/datasets/deepglobelandcover.py
+++ b/torchgeo/datasets/deepglobelandcover.py
@@ -62,8 +62,18 @@ class DeepGlobeLandCover(NonGeoDataset):
 
     * https://arxiv.org/pdf/1805.06561.pdf
 
+    .. note::
+
+       This dataset can be downloaded using:
+
+       .. code-block:: console
+
+          $ pip install kaggle  # place api key at ~/.kaggle/kaggle.json
+          $ kaggle datasets download -d geoap96/deepglobe2018-landcover-segmentation-traindataset
+          $ unzip deepglobe2018-landcover-segmentation-traindataset.zip
+
     .. versionadded:: 0.3
-    """
+    """  # noqa: E501
 
     filename = "data.zip"
     data_root = "data"


Test patch:
Repository: microsoft/torchgeo

Issue:
PatternNet download link is broken
### Description

[PatterNet dataset](https://torchgeo.readthedocs.io/en/stable/_modules/torchgeo/datasets/patternnet.html#PatternNet) [download link ](https://drive.google.com/file/d/127lxXYqzO6Bd0yZhvEbgIfz95HaEnr9K) is broken.

It seems it is officially hosted [here](https://nuisteducn1-my.sharepoint.com/:u:/g/personal/zhouwx_nuist_edu_cn/EYSPYqBztbBBqS27B7uM_mEB3R9maNJze8M1Qg9Q6cnPBQ?e=MSf977). Was someone mirroring it on a personal Google Drive? 

### Steps to reproduce

```
from torchgeo.datasets import PatternNet

patternet = PatternNet(root='./', transforms=None, download=True, checksum=True)
```

### Version

0.5.2


Discussion:
That URL can't be downloaded automatically, seems to require manual clicking.

Personally, I would try to reach out to the author and ask what license the dataset is distributed under. If it allows redistribution, we can rehost it on Hugging Face and make it much easier to download.
Just sent an email asking about the license and whether we can host it on HF!

Resolving patch:
diff --git a/torchgeo/datasets/patternnet.py b/torchgeo/datasets/patternnet.py
--- a/torchgeo/datasets/patternnet.py
+++ b/torchgeo/datasets/patternnet.py
@@ -78,7 +78,7 @@ class PatternNet(NonGeoClassificationDataset):
     * https://doi.org/10.1016/j.isprsjprs.2018.01.004
     """
 
-    url = 'https://drive.google.com/file/d/127lxXYqzO6Bd0yZhvEbgIfz95HaEnr9K'
+    url = 'https://hf.co/datasets/torchgeo/PatternNet/resolve/2dbd901b00e301967a5c5146b25454f5d3455ad0/PatternNet.zip'
     md5 = '96d54b3224c5350a98d55d5a7e6984ad'
     filename = 'PatternNet.zip'
     directory = os.path.join('PatternNet', 'images')


Test patch:
Repository: keras-team/keras-nlp

Issue:
Typo in TransformerEncoder doc-string
Noticed a minor issue (typo) in the doc-string of the TransformerEncoder Layer: https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/layers/transformer_encoder.py.

[Line 46](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/layers/transformer_encoder.py#L46)
[Line 50](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/layers/transformer_encoder.py#L50)
[Line 55](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/layers/transformer_encoder.py#L55)

It should be "encoder" instead of "decoder". I've opened a PR.

P.S. Not exactly a feature request, but not exactly a bug either...so, didn't know which category to put this issue under :P


Discussion:

Resolving patch:
diff --git a/keras_nlp/layers/transformer_encoder.py b/keras_nlp/layers/transformer_encoder.py
--- a/keras_nlp/layers/transformer_encoder.py
+++ b/keras_nlp/layers/transformer_encoder.py
@@ -43,16 +43,16 @@ class TransformerEncoder(keras.layers.Layer):
     Examples:
 
     ```python
-    # Create a single transformer decoder layer.
+    # Create a single transformer encoder layer.
     encoder = keras_nlp.layer.TransformerEncoder(
         intermediate_dim=64, num_heads=8)
 
-    # Create a simple model containing the decoder.
+    # Create a simple model containing the encoder.
     input = tf.keras.Input(shape=[4, 6])
     output = encoder(input)
     model = tf.keras.Model(inputs=input, outputs=output)
 
-    # Call decoder on the inputs.
+    # Call encoder on the inputs.
     input_data = tf.random.uniform(shape=[1, 10, 64])
     output = model(input_data)
 


Test patch:
Repository: keras-team/keras-nlp

Issue:
Broken Imports
I think I broke the library as now there are errors due to the utils directory added in the last PR. I think this is because I forgot to add a `__init__` file for the utils folder. I'll create a PR to fix this as locally this seems to fix the issue.

Demo for what's broken is [here](https://colab.research.google.com/gist/aflah02/7f06a9bf29dd0edc5d2aeff9e55c4633/untitled16.ipynb)


Discussion:

Resolving patch:
diff --git a/keras_nlp/utils/__init__.py b/keras_nlp/utils/__init__.py
new file mode 100644
--- /dev/null
+++ b/keras_nlp/utils/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2022 The KerasNLP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.


Test patch:
diff --git a/keras_nlp/utils/tensor_utils_test.py b/keras_nlp/utils/tensor_utils_test.py
--- a/keras_nlp/utils/tensor_utils_test.py
+++ b/keras_nlp/utils/tensor_utils_test.py
@@ -13,7 +13,8 @@
 # limitations under the License.
 
 import tensorflow as tf
-from tensor_utils import tensor_to_string_list
+
+from keras_nlp.utils.tensor_utils import tensor_to_string_list
 
 
 class TensorToStringListTest(tf.test.TestCase):
Repository: keras-team/keras-nlp

Issue:
Why does the docstring say vocab size should be no larger than 999?
https://github.com/keras-team/keras-nlp/blob/e3adddaa98bbe1aee071117c01678fe3017dae80/keras_nlp/layers/token_and_position_embedding.py#L30

Seems like a very small vocab to me


Discussion:
Thanks, good catch! Yeah that's not a real requirement. The guide we just published uses the layer with a 30k vocabulary (and there is not hard limit that I'm aware of, just memory constraints).

Not sure how that got there but let's remove!

Resolving patch:
diff --git a/keras_nlp/layers/token_and_position_embedding.py b/keras_nlp/layers/token_and_position_embedding.py
--- a/keras_nlp/layers/token_and_position_embedding.py
+++ b/keras_nlp/layers/token_and_position_embedding.py
@@ -26,8 +26,7 @@ class TokenAndPositionEmbedding(keras.layers.Layer):
     to the sequence dimension.
 
     Args:
-        vocabulary_size: The size of the vocabulary (should be no larger
-            than 999)
+        vocabulary_size: The size of the vocabulary.
         sequence_length: The maximum length of input sequence
         embedding_dim: The output dimension of the embedding layer
         embeddings_initializer: The initializer to use for the Embedding


Test patch:
Repository: keras-team/keras-nlp

Issue:
Update our glue evaluation script to use tensorflow datasets
When it was originally written, glue for tfds was totally broken, so we used huggingface datasets.

This appears to be fixed, so let's used tfds instead.

We should update the line here as well to flip the dependency.
https://github.com/keras-team/keras-nlp/blob/master/setup.py#L55


Discussion:

Resolving patch:
diff --git a/examples/bert/bert_finetune_glue.py b/examples/bert/bert_finetune_glue.py
--- a/examples/bert/bert_finetune_glue.py
+++ b/examples/bert/bert_finetune_glue.py
@@ -15,9 +15,9 @@
 
 import tempfile
 
-import datasets
 import keras_tuner
 import tensorflow as tf
+import tensorflow_datasets as tfds
 from absl import app
 from absl import flags
 from tensorflow import keras
@@ -77,7 +77,7 @@ def load_data(task_name):
     elif task_name in "qqp":
         feature_names = ("question1", "question2")
     else:
-        raise ValueError(f"Unkown task_name {task_name}.")
+        raise ValueError(f"Unknown task_name {task_name}.")
 
     test_suffix = ""
     if task_name in ("mnli", "mnli_matched"):
@@ -88,17 +88,18 @@ def load_data(task_name):
         task_name = "mnli"
         test_suffix = "_mismatched"
 
-    def to_tf_dataset(split):
-        # Format each sample as a tuple of string features and an int label.
-        features = tuple([split[f] for f in feature_names])
-        label = tf.cast(split["label"], tf.int32)
-        return tf.data.Dataset.from_tensor_slices((features, label))
-
-    data = datasets.load_dataset("glue", task_name)
-    data.set_format(type="tensorflow")
-    train_ds = to_tf_dataset(data["train"])
-    test_ds = to_tf_dataset(data["test" + test_suffix])
-    validation_ds = to_tf_dataset(data["validation" + test_suffix])
+    def split_features(x):
+        return {feature_name: x[feature_name] for feature_name in feature_names}
+
+    train_ds, test_ds, validation_ds = tfds.load(
+        f"glue/{task_name}",
+        split=["train", "test" + test_suffix, "validation" + test_suffix],
+    )
+    train_ds = train_ds.map(split_features, num_parallel_calls=tf.data.AUTOTUNE)
+    test_ds = test_ds.map(split_features, num_parallel_calls=tf.data.AUTOTUNE)
+    validation_ds = validation_ds.map(
+        split_features, num_parallel_calls=tf.data.AUTOTUNE
+    )
     return train_ds, test_ds, validation_ds
 
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -52,7 +52,7 @@
             "sentencepiece",
         ],
         "examples": [
-            "datasets",  # For GLUE in BERT example.
+            "tensorflow_datasets",  # For GLUE in BERT example.
             "nltk",
             "wikiextractor",
             "keras-tuner",


Test patch:
Repository: keras-team/keras-nlp

Issue:
Call `super.config()` in `BartBackbone`'s `get_config()`
We should call `super().config()` here: https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/bart/bart_backbone.py#L238, update the config with `BARTBackbone`-specific keys and return the config. Check this for reference: https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/bert/bert_backbone.py#L204.


Discussion:
@Rayquaza6102, would you like to take up this issue?
Hi @abheesht17 can I take this issue?

Resolving patch:
diff --git a/keras_nlp/models/bart/bart_backbone.py b/keras_nlp/models/bart/bart_backbone.py
--- a/keras_nlp/models/bart/bart_backbone.py
+++ b/keras_nlp/models/bart/bart_backbone.py
@@ -236,17 +236,20 @@ def __init__(
         self.max_sequence_length = max_sequence_length
 
     def get_config(self):
-        return {
-            "vocabulary_size": self.vocabulary_size,
-            "num_layers": self.num_layers,
-            "num_heads": self.num_heads,
-            "hidden_dim": self.hidden_dim,
-            "intermediate_dim": self.intermediate_dim,
-            "dropout": self.dropout,
-            "max_sequence_length": self.max_sequence_length,
-            "name": self.name,
-            "trainable": self.trainable,
-        }
+        config = super().get_config()
+        config.update(
+            {
+                "vocabulary_size": self.vocabulary_size,
+                "num_layers": self.num_layers,
+                "num_heads": self.num_heads,
+                "hidden_dim": self.hidden_dim,
+                "intermediate_dim": self.intermediate_dim,
+                "dropout": self.dropout,
+                "max_sequence_length": self.max_sequence_length,
+            }
+        )
+
+        return config
 
     @property
     def token_embedding(self):


Test patch:
Repository: keras-team/keras-nlp

Issue:
Remove API export decorator from base classes
We should remove the API export decorator from base classes like [`Backbone`](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/backbone.py#L26-L27), [`Preprocessor`](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/preprocessor.py#L22-L23), [`Task`](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/task.py#L26-L27) and [`Tokenizer`](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/tokenizers/tokenizer.py#L22-L23). These classes are meant to be used internally.


Discussion:
@shivance, would you like to take this up?
Sure, piece of cake.
btw @abheesht17 , if that's the case we should remove it from `Sampler` as well.

Resolving patch:
diff --git a/keras_nlp/models/backbone.py b/keras_nlp/models/backbone.py
--- a/keras_nlp/models/backbone.py
+++ b/keras_nlp/models/backbone.py
@@ -18,12 +18,11 @@
 
 from tensorflow import keras
 
-from keras_nlp.api_export import keras_nlp_export
 from keras_nlp.utils.python_utils import classproperty
 from keras_nlp.utils.python_utils import format_docstring
 
 
-@keras_nlp_export("keras_nlp.models.Backbone")
+@keras.utils.register_keras_serializable(package="keras_nlp")
 class Backbone(keras.Model):
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
diff --git a/keras_nlp/models/preprocessor.py b/keras_nlp/models/preprocessor.py
--- a/keras_nlp/models/preprocessor.py
+++ b/keras_nlp/models/preprocessor.py
@@ -14,12 +14,11 @@
 
 from tensorflow import keras
 
-from keras_nlp.api_export import keras_nlp_export
 from keras_nlp.utils.python_utils import classproperty
 from keras_nlp.utils.python_utils import format_docstring
 
 
-@keras_nlp_export("keras_nlp.models.Preprocessor")
+@keras.utils.register_keras_serializable(package="keras_nlp")
 class Preprocessor(keras.layers.Layer):
     """Base class for model preprocessors."""
 
diff --git a/keras_nlp/models/task.py b/keras_nlp/models/task.py
--- a/keras_nlp/models/task.py
+++ b/keras_nlp/models/task.py
@@ -17,13 +17,12 @@
 
 from tensorflow import keras
 
-from keras_nlp.api_export import keras_nlp_export
 from keras_nlp.utils.pipeline_model import PipelineModel
 from keras_nlp.utils.python_utils import classproperty
 from keras_nlp.utils.python_utils import format_docstring
 
 
-@keras_nlp_export("keras_nlp.models.Task")
+@keras.utils.register_keras_serializable(package="keras_nlp")
 class Task(PipelineModel):
     """Base class for Task models."""
 


Test patch: