nshtrainer 0.40.2__py3-none-any.whl → 0.40.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nshtrainer/_hf_hub.py CHANGED
@@ -5,11 +5,11 @@ import re
5
5
  from dataclasses import dataclass
6
6
  from functools import cached_property
7
7
  from pathlib import Path
8
- from typing import TYPE_CHECKING, Any, cast
8
+ from typing import TYPE_CHECKING, Any, Literal, cast
9
9
 
10
10
  import nshconfig as C
11
11
  from nshrunner._env import SNAPSHOT_DIR
12
- from typing_extensions import override
12
+ from typing_extensions import assert_never, override
13
13
 
14
14
  from ._callback import NTCallbackBase
15
15
  from .callbacks.base import CallbackConfigBase
@@ -65,6 +65,9 @@ class HuggingFaceHubConfig(CallbackConfigBase):
65
65
  """Whether to save to the Hugging Face Hub in the background.
66
66
  This corresponds to setting `run_as_future=True` in the HFApi upload methods."""
67
67
 
68
+ on_login_error: Literal["warn", "error", "ignore"] = "warn"
69
+ """What to do when an error occurs during login."""
70
+
68
71
  def enable_(self):
69
72
  self.enabled = True
70
73
  return self
@@ -78,6 +81,30 @@ class HuggingFaceHubConfig(CallbackConfigBase):
78
81
 
79
82
  @override
80
83
  def create_callbacks(self, root_config):
84
+ # Attempt to login. If it fails, we'll log a warning or error based on the configuration.
85
+ try:
86
+ api = _api(self.token)
87
+ if api is None:
88
+ raise ValueError("Failed to create Hugging Face Hub API instance.")
89
+ except Exception as e:
90
+ match self.on_login_error:
91
+ case "warn":
92
+ log.warning(
93
+ "Failed to create Hugging Face Hub API instance. Disabling Hugging Face Hub integration.",
94
+ exc_info=e,
95
+ )
96
+ return
97
+ case "error":
98
+ raise
99
+ case "ignore":
100
+ log.debug(
101
+ "Failed to create Hugging Face Hub API instance. Disabling Hugging Face Hub integration.",
102
+ exc_info=e,
103
+ )
104
+ return
105
+ case _:
106
+ assert_never(self.on_login_error)
107
+
81
108
  yield self.with_metadata(HFHubCallback(self), ignore_if_exists=True)
82
109
 
83
110
 
@@ -77,7 +77,7 @@ class BaseConfig(C.Config):
77
77
  return self.directory.resolve_subdirectory(self.id, subdirectory)
78
78
 
79
79
  # region Helper methods
80
- def fast_dev_run(self, value: int | bool, /):
80
+ def fast_dev_run(self, value: int | bool = True, /):
81
81
  """
82
82
  Enables fast_dev_run mode for the trainer.
83
83
  This will run the training loop for a specified number of batches,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nshtrainer
3
- Version: 0.40.2
3
+ Version: 0.40.4
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -5,7 +5,7 @@ nshtrainer/_checkpoint/metadata.py,sha256=5D4PgKodzhLsmQvuF3xxkH49epKaegxi4wh_Im
5
5
  nshtrainer/_checkpoint/saver.py,sha256=xuA9iDpc4wAs4ieYW1eJoJicMn6e5xCeCIEKfVOCvrY,1324
6
6
  nshtrainer/_directory.py,sha256=RjnW6vKTeKlz2vQWT3cG0Jje5BkFXA7HpUubDhcSiq4,2993
7
7
  nshtrainer/_experimental/__init__.py,sha256=pEXPyI184UuDHvfh4p9Kg9nQZQZI41e4_HvNd4BK-yg,81
8
- nshtrainer/_hf_hub.py,sha256=0bkXkqhve5D1onMW-fCfuvVKlTn0i6jv_6uMNgZ7OHQ,12974
8
+ nshtrainer/_hf_hub.py,sha256=woRRy9bzAQ8ueoH903CzYGjQYZ0Cp7Hw5uv8qgLnZ5o,14105
9
9
  nshtrainer/callbacks/__init__.py,sha256=y4QKDiI4IykcHncDOE-OemFFQqegxyeoD_3v9i2OwFw,3248
10
10
  nshtrainer/callbacks/_throughput_monitor_callback.py,sha256=aJo_11rc4lo0IYOd-kHmPDtzdC4ctgXyRudkRJqH4m4,23184
11
11
  nshtrainer/callbacks/actsave.py,sha256=qbnaKts4_dvjPeAaPtv7Ds12_vEWzaHUfg_--49NB9I,4041
@@ -66,7 +66,7 @@ nshtrainer/metrics/__init__.py,sha256=ObLIELGguIEcUpRsUkqh1ltrvZii6vglTpJGrPvoy0
66
66
  nshtrainer/metrics/_config.py,sha256=jgRBfDAQLFTW7AiUY7CRtdfts6CR6keeuqm0FFMWCzQ,1288
67
67
  nshtrainer/model/__init__.py,sha256=2i_VEy6u_Y1LUGKljHXWeekvhnUcanZM2QyaaBM1Bmw,261
68
68
  nshtrainer/model/base.py,sha256=NasbYZJBuEly6Hm9t9HVZk-CUHmy4T7p1v-Ye981XA4,18609
69
- nshtrainer/model/config.py,sha256=tZg6qsHwyhYFLe7MQx_y2HRPVgnt8WZAB3DpsOb0uso,6954
69
+ nshtrainer/model/config.py,sha256=gyP5uuDfl4EbkmFlqnpNm49D0PgJWK9S6UOFGGaAAtQ,6961
70
70
  nshtrainer/model/mixins/callback.py,sha256=rbe8P22iEjPkH1df6rfEo3Txw7EwSz6Dkm0TWO_AysM,2419
71
71
  nshtrainer/model/mixins/logger.py,sha256=xOymSTofukEYZGkGojXsMEO__ZlBI5lIPZVmlotMEX8,5291
72
72
  nshtrainer/nn/__init__.py,sha256=0QPFl02a71WZQjLMGOlFNMmsYP5aa1q3eABHmnWH58Q,1427
@@ -100,6 +100,6 @@ nshtrainer/util/seed.py,sha256=Or2wMPsnQxfnZ2xfBiyMcHFIUt3tGTNeMMyOEanCkqs,280
100
100
  nshtrainer/util/slurm.py,sha256=rofIU26z3SdL79SF45tNez6juou1cyDLz07oXEZb9Hg,1566
101
101
  nshtrainer/util/typed.py,sha256=NGuDkDzFlc1fAoaXjOFZVbmj0mRFjsQi1E_hPa7Bn5U,128
102
102
  nshtrainer/util/typing_utils.py,sha256=8ptjSSLZxlmy4FY6lzzkoGoF5fGNClo8-B_c0XHQaNU,385
103
- nshtrainer-0.40.2.dist-info/METADATA,sha256=yeuMHfYVmcPkNcPveUU1Rq38HeIunxERh4gqvzy85Uc,916
104
- nshtrainer-0.40.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
105
- nshtrainer-0.40.2.dist-info/RECORD,,
103
+ nshtrainer-0.40.4.dist-info/METADATA,sha256=WEVuvm57GaDclfY6NGCfcUuyiaGyF8iljtBvy4uyUX8,916
104
+ nshtrainer-0.40.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
105
+ nshtrainer-0.40.4.dist-info/RECORD,,