iapytoo 0.0.4.dev3__py3-none-any.whl → 0.0.6.dev0__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.

Potentially problematic release.


This version of iapytoo might be problematic. Click here for more details.

Files changed (37) hide show
  1. dockers/docker-compose.yml +15 -0
  2. dockers/requirements.txt +6 -0
  3. dockers/run-python.sh +1 -2
  4. examples/zipped_runs/selected_runs.zip +0 -0
  5. iapytoo/_version.py +9 -4
  6. iapytoo/dataset/__init__.py +4 -8
  7. iapytoo/metrics/__init__.py +7 -7
  8. iapytoo/metrics/metric.py +16 -9
  9. iapytoo/metrics/predefined.py +13 -12
  10. iapytoo/predictions/__init__.py +17 -42
  11. iapytoo/predictions/feature.py +1 -2
  12. iapytoo/predictions/plotters.py +39 -11
  13. iapytoo/predictions/predictors.py +20 -2
  14. iapytoo/predictions/types.py +0 -2
  15. iapytoo/train/checkpoint.py +18 -9
  16. iapytoo/train/factories.py +32 -26
  17. iapytoo/train/inference.py +93 -0
  18. iapytoo/train/logger.py +65 -54
  19. iapytoo/train/loss.py +4 -5
  20. iapytoo/train/mlflow_model.py +80 -0
  21. iapytoo/train/training.py +72 -91
  22. iapytoo/train/valuator.py +43 -0
  23. iapytoo/train/wgan.py +114 -39
  24. iapytoo/utils/arguments.py +19 -34
  25. iapytoo/utils/cf/config.yml +21 -0
  26. iapytoo/utils/config.py +300 -79
  27. iapytoo/utils/model_config.py +72 -0
  28. iapytoo/utils/singleton.py +15 -0
  29. {iapytoo-0.0.4.dev3.dist-info → iapytoo-0.0.6.dev0.dist-info}/METADATA +3 -2
  30. iapytoo-0.0.6.dev0.dist-info/RECORD +49 -0
  31. {iapytoo-0.0.4.dev3.dist-info → iapytoo-0.0.6.dev0.dist-info}/WHEEL +1 -1
  32. {iapytoo-0.0.4.dev3.dist-info → iapytoo-0.0.6.dev0.dist-info}/top_level.txt +2 -0
  33. mlflow/relocate_mlruns.py +67 -0
  34. mlflow/zip_selected_runs.py +80 -0
  35. iapytoo/utils/meta_singleton.py +0 -17
  36. iapytoo-0.0.4.dev3.dist-info/RECORD +0 -39
  37. {iapytoo-0.0.4.dev3.dist-info → iapytoo-0.0.6.dev0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,15 @@
1
+ version: "3.8"
2
+
3
+ services:
4
+ iapytoo:
5
+ build:
6
+ context: .
7
+ dockerfile: Dockerfile.ifpen
8
+ args:
9
+ http_proxy: ${http_proxy}
10
+ https_proxy: ${https_proxy}
11
+ no_proxy: ${no_proxy}
12
+ image: iapytoo:latest
13
+
14
+ env_file:
15
+ - .env
@@ -0,0 +1,6 @@
1
+ tqdm
2
+ numpy
3
+ matplotlib
4
+ mlflow
5
+ seaborn
6
+ iapytoo
dockers/run-python.sh CHANGED
@@ -5,5 +5,4 @@ docker run --rm --gpus all \
5
5
  -w /app \
6
6
  -e PYTHONPATH=/app \
7
7
  iapytoo:latest \
8
- python3 examples/mnist.py -c examples/config_mnist.json data
9
-
8
+ python3 examples/mnist.py --yaml examples/config_mnist.yml
Binary file
iapytoo/_version.py CHANGED
@@ -1,8 +1,13 @@
1
- # file generated by setuptools_scm
1
+ # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
3
6
  TYPE_CHECKING = False
4
7
  if TYPE_CHECKING:
5
- from typing import Tuple, Union
8
+ from typing import Tuple
9
+ from typing import Union
10
+
6
11
  VERSION_TUPLE = Tuple[Union[int, str], ...]
7
12
  else:
8
13
  VERSION_TUPLE = object
@@ -12,5 +17,5 @@ __version__: str
12
17
  __version_tuple__: VERSION_TUPLE
13
18
  version_tuple: VERSION_TUPLE
14
19
 
15
- __version__ = version = '0.0.4.dev3'
16
- __version_tuple__ = version_tuple = (0, 0, 4, 'dev3')
20
+ __version__ = version = '0.0.6.dev0'
21
+ __version_tuple__ = version_tuple = (0, 0, 6, 'dev0')
@@ -13,8 +13,7 @@ class DummyVisionDataset(VisionDataset):
13
13
  np.random.seed(12)
14
14
  A = np.array(range(self.dim * self.dim)).reshape((self.dim, self.dim))
15
15
  self.images = np.zeros(
16
- shape=(self.length, self.n_channels,
17
- self.dim, self.dim), dtype=np.float32
16
+ shape=(self.length, self.n_channels, self.dim, self.dim), dtype=np.float32
18
17
  )
19
18
  for idx in range(self.length):
20
19
  for c in range(self.n_channels):
@@ -24,10 +23,8 @@ class DummyVisionDataset(VisionDataset):
24
23
 
25
24
  self.targets = np.vstack(
26
25
  [
27
- np.array(range(self.length)) +
28
- np.random.normal(size=(self.length)),
29
- np.array(range(self.length)) +
30
- np.random.normal(size=(self.length)),
26
+ np.array(range(self.length)) + np.random.normal(size=(self.length)),
27
+ np.array(range(self.length)) + np.random.normal(size=(self.length)),
31
28
  ]
32
29
  )
33
30
 
@@ -49,8 +46,7 @@ class DummyLabelDataset(VisionDataset):
49
46
  np.random.seed(12)
50
47
  A = np.array(range(self.dim * self.dim)).reshape((self.dim, self.dim))
51
48
  self.images = np.zeros(
52
- shape=(self.length, self.n_channels,
53
- self.dim, self.dim), dtype=np.float32
49
+ shape=(self.length, self.n_channels, self.dim, self.dim), dtype=np.float32
54
50
  )
55
51
  for idx in range(self.length):
56
52
  for c in range(self.n_channels):
@@ -1,13 +1,12 @@
1
- import torch
2
-
3
- from iapytoo.utils.meta_singleton import MetaSingleton
4
1
 
2
+ from iapytoo.utils.config import Config
3
+ from iapytoo.utils.singleton import singleton
5
4
  from .predefined import R2Metric, RMSMetric, MSMetric, AccuracyMetric
6
5
  from .metric import Metric
7
6
 
8
7
 
9
8
  class MetricsCollection(Metric):
10
- def __init__(self, tag: str, metric_names: list, config):
9
+ def __init__(self, tag: str, metric_names: list[str], config: Config):
11
10
  super().__init__(tag, config)
12
11
  self.metrics = {}
13
12
  factory = MetricFactory()
@@ -33,7 +32,7 @@ class MetricsCollection(Metric):
33
32
  results = m.compute()
34
33
  for name, result in results.items():
35
34
  # prepend the name of the collection to all inner results : validation_accuracy for example
36
- self.results[f'{self.name}_{name}'] = result
35
+ self.results[f"{self.name}_{name}"] = result
37
36
  return self.results
38
37
 
39
38
  # overwrite
@@ -47,7 +46,8 @@ class MetricError(Exception):
47
46
  super().__init__(*args)
48
47
 
49
48
 
50
- class MetricFactory(metaclass=MetaSingleton):
49
+ @singleton
50
+ class MetricFactory:
51
51
  def __init__(self) -> None:
52
52
  self.metrics_dict = {
53
53
  "r2": R2Metric,
@@ -59,7 +59,7 @@ class MetricFactory(metaclass=MetaSingleton):
59
59
  def register_metric(self, key, metric_cls):
60
60
  self.metrics_dict[key] = metric_cls
61
61
 
62
- def create_metric(self, kind: str, config: dict, device="cpu") -> Metric:
62
+ def create_metric(self, kind: str, config: Config, device="cpu") -> Metric:
63
63
  """Creates an architecture of NN
64
64
 
65
65
  Args:
iapytoo/metrics/metric.py CHANGED
@@ -1,39 +1,46 @@
1
1
  import torch
2
2
 
3
+ from iapytoo.utils.config import Config
4
+ from iapytoo.predictions.predictors import PredictorFactory
5
+
3
6
 
4
7
  class Metric:
5
- def __init__(self, name, config, with_target=True):
8
+ def __init__(self, name, config: Config, with_target=True):
6
9
  self.with_target = with_target
7
10
  self.name = name
8
11
  self.config = config
12
+ self.predictor = PredictorFactory().create_predictor(config)
9
13
 
10
14
  # First dimension is for the concatenation.
11
- self.predicted = torch.zeros(size=(0,))
15
+ self.outputs = torch.zeros(size=(0,))
12
16
  if self.with_target:
13
17
  self.target = torch.zeros(size=(0,))
14
18
  self.results = {}
15
19
 
16
20
  @property
17
21
  def device(self):
18
- return self.predicted.device
22
+ return self.outputs.device
23
+
24
+ @property
25
+ def predicted(self):
26
+ return self.predictor(self.outputs) if self.predictor else self.outputs
19
27
 
20
28
  def to(self, device):
21
- self.predicted = self.predicted.to(device)
29
+ self.outputs = self.outputs.to(device)
22
30
  if self.with_target:
23
31
  self.target = self.target.to(device)
24
32
  return self
25
33
 
26
- def update(self, Y_hat, Y):
27
- self.predicted = torch.cat((self.predicted, Y_hat), dim=0)
34
+ def update(self, outputs, Y):
35
+ self.outputs = torch.cat((self.outputs, outputs), dim=0)
28
36
  if self.with_target:
29
37
  self.target = torch.cat((self.target, Y), dim=0)
30
38
 
31
39
  def reset(self):
32
40
  device = self.device
33
- self.predicted = torch.zeros(size=self.output_size, device=device)
41
+ self.outputs = torch.zeros(size=(0,), device=device)
34
42
  if self.with_target:
35
- self.target = torch.zeros(
36
- size=self.output_size, device=self.device)
43
+ self.target = torch.zeros(size=(0,), device=self.device)
37
44
 
38
45
  def compute(self):
39
46
  pass
@@ -1,34 +1,35 @@
1
-
2
1
  import torch
2
+
3
+ from iapytoo.utils.config import Config
3
4
  from iapytoo.metrics.metric import Metric
4
5
 
5
6
 
6
7
  class AccuracyMetric(Metric):
7
- def __init__(self, config):
8
+ def __init__(self, config: Config):
8
9
  super(AccuracyMetric, self).__init__("accuracy", config)
9
- self.k = config['top_accuracy']
10
+ self.k = config.metrics.top_accuracy
10
11
 
11
12
  def compute(self):
12
13
 
13
14
  # Take care, for this metrics predicted and target do not have the same shape.
14
15
  # predicted : ouputs of the models - kind of probabilities
15
16
  # Target : label of the class
16
- _, top_pred = self.predicted.topk(self.k, 1)
17
+ _, top_pred = self.outputs.topk(self.k, 1)
17
18
  top_pred = top_pred.t()
18
19
  correct = top_pred.eq(self.target.view(1, -1).expand_as(top_pred))
19
20
  correct_1 = correct[:1].reshape(-1).float().sum(0, keepdim=True)
20
- correct_k = correct[:self.k].reshape(-1).float().sum(0, keepdim=True)
21
+ correct_k = correct[: self.k].reshape(-1).float().sum(0, keepdim=True)
21
22
 
22
23
  return {
23
- 'top-1': torch.round(
24
- 100.0 * correct_1 / self.target.shape[0], decimals=2),
25
- f'top-{self.k}': torch.round(
26
- 100.0 * correct_k / self.target.shape[0], decimals=2)
24
+ "top-1": torch.round(100.0 * correct_1 / self.target.shape[0], decimals=2),
25
+ f"top-{self.k}": torch.round(
26
+ 100.0 * correct_k / self.target.shape[0], decimals=2
27
+ ),
27
28
  }
28
29
 
29
30
 
30
31
  class R2Metric(Metric):
31
- def __init__(self, config) -> None:
32
+ def __init__(self, config: Config) -> None:
32
33
  super(R2Metric, self).__init__("r2", config)
33
34
 
34
35
  def compute(self):
@@ -49,7 +50,7 @@ class R2Metric(Metric):
49
50
 
50
51
 
51
52
  class MSMetric(Metric):
52
- def __init__(self, config) -> None:
53
+ def __init__(self, config: Config) -> None:
53
54
  super(MSMetric, self).__init__("mean_square", config)
54
55
 
55
56
  def _compute(self):
@@ -63,7 +64,7 @@ class MSMetric(Metric):
63
64
 
64
65
 
65
66
  class RMSMetric(MSMetric):
66
- def __init__(self, config) -> None:
67
+ def __init__(self, config: Config) -> None:
67
68
  Metric.__init__(self, "root_mean_square", config)
68
69
  self.name = "rms"
69
70
 
@@ -1,17 +1,19 @@
1
1
  import torch
2
- import numpy as np
3
2
 
3
+ from iapytoo.utils.config import Config
4
4
  from .types import PredictionType
5
5
  from .plotters import CollectionPlotters
6
- from .predictors import Predictor
6
+ from .predictors import PredictorFactory
7
+ from iapytoo.train.valuator import Valuator
7
8
 
8
9
 
9
10
  class Predictions:
10
- def __init__(self, predictor: Predictor, norm=False):
11
- self.norm = norm
11
+ def __init__(self, config: Config):
12
12
  self.outputs = None # dimension is assigned in compute
13
13
  self.actual = None
14
- self.predictor = predictor
14
+
15
+ self.predictor = PredictorFactory().create_predictor(config)
16
+
15
17
  self.prediction_plotter: CollectionPlotters = CollectionPlotters()
16
18
  self.prediction_plotter.connect(self)
17
19
 
@@ -22,35 +24,24 @@ class Predictions:
22
24
  def add_plotter(self, prediction_plotter):
23
25
  self.prediction_plotter.add(prediction_plotter)
24
26
 
25
- def compute(self, training, loader):
26
- device = training.device
27
- y_scaling = training.y_scaling
28
- self.outputs = torch.zeros(size=(0,), device=device)
29
- self.actual = torch.zeros(size=(0,), device=device)
27
+ def compute(self, loader, valuator: Valuator):
30
28
 
31
- model = training.model
32
- model.eval()
33
- with torch.no_grad():
34
- for X, Y in loader:
35
- X = X.to(device)
36
- Y = Y.to(device)
37
- model_output = model(X)
29
+ self.outputs = torch.zeros(size=(0,))
30
+ self.actual = torch.zeros(size=(0,))
38
31
 
39
- self.outputs = torch.cat((self.outputs, model_output), dim=0)
40
- self.actual = torch.cat((self.actual, Y), dim=0)
32
+ for outputs, actual in valuator.evaluate_loader(loader):
33
+ self.outputs = torch.cat((self.outputs, outputs), dim=0)
41
34
 
42
- if not self.norm and y_scaling is not None:
43
- self.outputs = y_scaling.inv(self.outputs)
44
- self.actual = y_scaling.inv(self.actual)
35
+ if actual is not None:
36
+ self.actual = torch.cat((self.actual, actual), dim=0)
45
37
 
46
38
  def tensor(self, type: PredictionType = PredictionType.PREDICTED):
47
39
  if type == PredictionType.PREDICTED:
48
- predicted = self.predictor(self.outputs)
49
- return predicted.detach().cpu()
40
+ return self.predictor(self.outputs) if self.predictor else self.outputs
50
41
  elif type == PredictionType.ACTUAL:
51
- return self.actual.detach().cpu()
42
+ return self.actual
52
43
  else:
53
- return self.outputs.detach().cpu()
44
+ return self.outputs
54
45
 
55
46
  def numpy(self, type: PredictionType = PredictionType.PREDICTED):
56
47
  return self.tensor(type).numpy()
@@ -60,19 +51,3 @@ class Predictions:
60
51
  return self.prediction_plotter.plot(epoch)
61
52
  else:
62
53
  return {} # nothing to plot
63
-
64
-
65
- class GenerativePredictions(Predictions):
66
- def __init__(self, norm=False):
67
- super().__init__(norm)
68
-
69
- def compute(self, training, loader):
70
- device = training.device
71
- self.outputs = torch.zeros(size=(0,), device=device)
72
- generator = training.generator
73
- generator.eval()
74
- with torch.no_grad():
75
- for X in loader:
76
- X = X.to(device)
77
- gen_output = generator(X)
78
- self.outputs = torch.cat((self.outputs, gen_output), dim=0)
@@ -11,6 +11,5 @@ class Feature:
11
11
  for i in range(predictions.actual.shape[0]):
12
12
  actual_del = self.computer(predictions.actual[i, 0, :], **kwargs)
13
13
  self.actual.append(actual_del)
14
- predicted_del = self.computer(
15
- predictions.outputs[i, 0, :], **kwargs)
14
+ predicted_del = self.computer(predictions.outputs[i, 0, :], **kwargs)
16
15
  self.predicted.append(predicted_del)
@@ -7,10 +7,12 @@ from scipy.signal import welch
7
7
  import numpy as np
8
8
 
9
9
  from iapytoo.predictions.types import PredictionType
10
+ from iapytoo.utils.config import Config
11
+ from iapytoo.utils.singleton import singleton
10
12
 
11
13
 
12
14
  class PredictionPlotter:
13
- def __init__(self, title=None):
15
+ def __init__(self, title=None, config: Config | None = None):
14
16
  self.predictions = None
15
17
  self.title = title
16
18
 
@@ -23,7 +25,7 @@ class PredictionPlotter:
23
25
 
24
26
  class CollectionPlotters(PredictionPlotter):
25
27
 
26
- def __init__(self, title=None):
28
+ def __init__(self, title=None, config: Config | None = None):
27
29
  super(CollectionPlotters, self).__init__(title)
28
30
  self.plotters = []
29
31
 
@@ -43,7 +45,7 @@ class CollectionPlotters(PredictionPlotter):
43
45
 
44
46
 
45
47
  class ScatterPlotter(PredictionPlotter):
46
- def __init__(self):
48
+ def __init__(self, config: Config | None = None):
47
49
  super().__init__(title="actual_versus_predicted")
48
50
 
49
51
  def plot(self, epoch):
@@ -56,7 +58,7 @@ class ScatterPlotter(PredictionPlotter):
56
58
 
57
59
 
58
60
  class ConfusionPlotter(PredictionPlotter):
59
- def __init__(self):
61
+ def __init__(self, config: Config | None = None):
60
62
  super().__init__(title="confusion_matrix")
61
63
 
62
64
  def plot(self, epoch):
@@ -72,7 +74,7 @@ class ConfusionPlotter(PredictionPlotter):
72
74
 
73
75
  class TSNEPlotter(PredictionPlotter):
74
76
 
75
- def __init__(self):
77
+ def __init__(self, config: Config | None = None):
76
78
  super().__init__(title="tsne")
77
79
 
78
80
  def plot(self, epoch):
@@ -98,7 +100,7 @@ class TSNEPlotter(PredictionPlotter):
98
100
 
99
101
 
100
102
  class Fake1DPlotter(PredictionPlotter):
101
- def __init__(self, n_plot=4):
103
+ def __init__(self, n_plot=4, config: Config | None = None):
102
104
  super().__init__(title="generated_fake1d")
103
105
  self.n_plot = n_plot
104
106
 
@@ -107,7 +109,7 @@ class Fake1DPlotter(PredictionPlotter):
107
109
  f, a = plt.subplots(self.n_plot, self.n_plot, figsize=(8, 8))
108
110
  for i in range(self.n_plot):
109
111
  for j in range(self.n_plot):
110
- a[i][j].plot(fake[i * self.n_plot + j].view(-1))
112
+ a[i][j].plot(fake[i * self.n_plot + j, 0, :])
111
113
  a[i][j].set_xticks(())
112
114
  a[i][j].set_yticks(())
113
115
 
@@ -115,23 +117,26 @@ class Fake1DPlotter(PredictionPlotter):
115
117
 
116
118
 
117
119
  class DSPPlotter(PredictionPlotter):
118
- def __init__(self, f_max=4, nperseg=200):
120
+ def __init__(self, f_max=4, nperseg=200, config: Config | None = None):
119
121
  super().__init__(title="dsp")
120
122
  self.f_max = f_max
121
123
  self.nperseg = nperseg
122
124
 
123
125
  def plot(self, epoch):
124
- fake = self.predictions.predicted[0].view(-1)
126
+ fake = self.predictions.numpy(PredictionType.PREDICTED)
127
+ assert fake is not None and fake.shape[0] > 0, "no signal for DSP extraction"
125
128
  f, ax = plt.subplots()
126
129
 
127
- frequencies, power_spectrum = welch(fake, fs=self.f_max, nperseg=self.nperseg)
130
+ frequencies, power_spectrum = welch(
131
+ fake[0, 0, :], fs=self.f_max, nperseg=self.nperseg
132
+ )
128
133
  ax.plot(frequencies, power_spectrum)
129
134
 
130
135
  return {self.title: f}
131
136
 
132
137
 
133
138
  class Fake2DPlotter(PredictionPlotter):
134
- def __init__(self, n_plot=4):
139
+ def __init__(self, n_plot=4, config: Config | None = None):
135
140
  super().__init__("generated_fake2d")
136
141
  self.n_plot = n_plot
137
142
 
@@ -144,3 +149,26 @@ class Fake2DPlotter(PredictionPlotter):
144
149
  ax.imshow(grid_img.permute(1, 2, 0))
145
150
 
146
151
  return {self.title: f}
152
+
153
+
154
+ @singleton
155
+ class PlotterFactory:
156
+ def __init__(self) -> None:
157
+ self.plotter_dict: dict[str, type[PredictionPlotter]] = {
158
+ "scatter": ScatterPlotter,
159
+ "confusion": ConfusionPlotter,
160
+ "tsne": TSNEPlotter,
161
+ "fake1d": Fake1DPlotter,
162
+ "fake2d": Fake2DPlotter,
163
+ "dsp": DSPPlotter,
164
+ }
165
+
166
+ def register_plotter(self, key: str, plotter_cls: type[PredictionPlotter]) -> None:
167
+ self.plotter_dict[key] = plotter_cls
168
+
169
+ def create_plotter(self, kind, **kwargs) -> PredictionPlotter:
170
+ try:
171
+ plotter: PredictionPlotter = self.plotter_dict[kind](**kwargs)
172
+ except KeyError:
173
+ raise KeyError(f"Plotter {kind} doesn't exist")
174
+ return plotter
@@ -1,6 +1,8 @@
1
-
2
1
  import torch
3
2
 
3
+ from iapytoo.utils.singleton import singleton
4
+ from iapytoo.utils.config import Config
5
+
4
6
 
5
7
  class Predictor:
6
8
  def __call__(self, outputs: torch.Tensor) -> torch.Tensor:
@@ -9,7 +11,23 @@ class Predictor:
9
11
 
10
12
 
11
13
  class MaxPredictor(Predictor):
12
-
13
14
  def __call__(self, outputs: torch.Tensor) -> torch.Tensor:
14
15
  _, preds = torch.max(outputs.data, 1)
15
16
  return preds
17
+
18
+
19
+ @singleton
20
+ class PredictorFactory:
21
+ def __init__(self) -> None:
22
+ self.predictor_dict = {"max": MaxPredictor}
23
+
24
+ def create_predictor(self, key: Config | str):
25
+ if isinstance(key, Config):
26
+ config: Config = key
27
+ kind = config.model.predictor
28
+ else:
29
+ kind = key
30
+ if kind is not None:
31
+ return self.predictor_dict[kind]()
32
+
33
+ return None
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  from enum import IntEnum
4
2
 
5
3
 
@@ -7,22 +7,22 @@ import tempfile
7
7
  class CheckPoint:
8
8
  def __init__(self, run_id=None) -> None:
9
9
  self.params = {"run_id": run_id}
10
- if run_id is not None:
11
- run = mlflow.get_run(self.run_id)
12
- assert run is not None, f"unable to find run {self.run_id}"
10
+ artifact_uri = self.artifact_uri
11
+ if artifact_uri is not None:
13
12
  with tempfile.TemporaryDirectory() as tmpdir:
14
- local_artifact = mlflow.artifacts.download_artifacts(
15
- run.info.artifact_uri, dst_path=tmpdir
13
+ ck_path = mlflow.artifacts.download_artifacts(
14
+ artifact_uri=artifact_uri,
15
+ dst_path=tmpdir
16
16
  )
17
- ck_path = os.path.join(local_artifact, "checkpoints")
18
17
  files = []
19
18
  for f in os.listdir(ck_path):
20
19
  ck_name = os.path.join(ck_path, f)
21
- if os.path.isfile(ck_name):
20
+ if "checkpoint" in f and os.path.isfile(ck_name):
22
21
  files.append(ck_name)
23
22
  files.sort(key=lambda x: os.path.getmtime(x))
24
23
  ck_name = files[-1]
25
- self.params = torch.load(ck_name)
24
+ self.params = torch.load(
25
+ ck_name, weights_only=False)
26
26
  else:
27
27
  self.params["epoch"] = -1
28
28
 
@@ -30,6 +30,14 @@ class CheckPoint:
30
30
  def run_id(self):
31
31
  return self.params["run_id"]
32
32
 
33
+ @property
34
+ def artifact_uri(self):
35
+ if self.run_id is None:
36
+ return None
37
+ run = mlflow.get_run(self.run_id)
38
+ assert run is not None, f"unable to find run {self.run_id}"
39
+ return os.path.join(run.info.artifact_uri, "checkpoints")
40
+
33
41
  @property
34
42
  def epoch(self):
35
43
  return self.params["epoch"]
@@ -41,4 +49,5 @@ class CheckPoint:
41
49
 
42
50
  def init(self, training, only_model=False):
43
51
  if self.run_id is not None:
44
- training.load_state_dict(self.params["training"], only_model=only_model)
52
+ training.load_state_dict(
53
+ self.params["training"], only_model=only_model)