Skip to content

Commit e6403db

Browse files
author
Federico Errica
committed
removed data_list from repository, which was never used for years
1 parent 56ee6d0 commit e6403db

11 files changed

Lines changed: 116 additions & 579 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# Changelog
22

3-
## [1.5.0] Pytorch Automatic Mixed-Precision Support
3+
## [1.5.0] Pytorch Distributed Data Parallel and Automatic Mixed-Precision Support
44

55
## Added
66

7+
- added Distributed Data Parallel (DDP) training support that is automatically enabled when `device: cuda` and `gpus_per_task` is an integer greater than 1
8+
- added DDP-aware data loading through `DistributedSampler` for training splits, so each rank processes a distinct shard
9+
- added a DDP example configuration file at `examples/MODEL_CONFIGS/config_MLP_ddp.yml` and a lightweight smoke test script at `examples/toy_ddp_training_smoke.py`
710
- added optional AMP configuration (`engine.args.mixed_precision`, `engine.args.mixed_precision_dtype`) with dotted dtype paths (e.g. `torch.float16`) and autocast support on CUDA/CPU
811
- added configurable ordered model-selection criteria via `model_selection_criteria` (lexicographic comparison with per-criterion direction)
912

13+
1014
## Changed
1115

16+
- evaluator/experiment execution now forwards progress and termination signals correctly in both debug and non-debug modes when DDP is active
17+
- distributed helper utilities are now centralized in `mlwiz.training.distributed` for reuse across engine/experiment code paths
18+
- rank-0-only side effects are enforced for distributed runs (logging/progress/checkpoint-related writes), reducing file contention across ranks
1219
- model selection now supports metrics from both loss and score aggregates, and non-main metrics must explicitly specify `source: loss|score`
1320
- configuration validation now raises an error when both `model_selection_criteria` and `higher_results_are_better` are provided
1421
- updated `MODEL_CONFIGS` examples/integration configs and templates to use `model_selection_criteria` as the default specification

docs/intro.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MLWiz helps you to:
99
* reduce the amount of boilerplate code to write,
1010
* make it flexible enough to encompass a wide range of use cases for research.
1111
* support a number of different hardware set ups, including a cluster of nodes (using `Ray <https://docs.ray.io/en/latest/>`_),
12+
* run single-GPU or multi-GPU training (DDP) transparently through configuration only, with or without mixed-precision
1213

1314
To run an experiment, you usually rely on 2 **YAML configuration files**:
1415
* one to pre-process the dataset and create the data splits,

docs/tutorial.rst

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ explanation of each field as a comment:
114114
device: # cpu | cuda
115115
max_cpus: # > 1 for parallelism
116116
max_gpus: # > 0 for gpu usage (device must be cuda though)
117-
gpus_per_task: # percentage of gpus to allocate for each task
117+
gpus_per_task: # Ray GPUs per task: fraction (<=1) or integer (>1 enables DDP)
118118
gpus_subset: # optional, comma-separated list of gpu indices, e.g. 0,2. Used to force a particular subset of GPUs being used.
119119
120120
@@ -133,16 +133,16 @@ explanation of each field as a comment:
133133
134134
135135
# Experiment
136-
result_folder: # path of the folder where to store results
137-
exp_name: # name of the experiment
138-
experiment: # dotted path to experiment class
139-
model_selection_criteria: # ordered model-selection criteria
140-
- metric: main_score
141-
direction: max
142-
evaluate_every: # evaluate on train/val/test every `n` epochs and log results
143-
risk_assessment_training_runs: # how many final (model assessment) training runs to perform to mitigate bad initializations
144-
model_selection_training_runs: # how many training runs to perform for each hyper-parameter configuration in a specific inner fold
145-
training_timeout_seconds: # optional max time (in seconds) for a single training run (-1 disables the timeout)
136+
result_folder: # path of the folder where to store results
137+
exp_name: # name of the experiment
138+
experiment: # dotted path to experiment class
139+
model_selection_criteria: # ordered model-selection criteria
140+
- metric: main_score
141+
direction: max
142+
evaluate_every: # evaluate on train/val/test every `n` epochs and log results
143+
risk_assessment_training_runs: # how many final (model assessment) training runs to perform to mitigate bad initializations
144+
model_selection_training_runs: # how many training runs to perform for each hyper-parameter configuration in a specific inner fold
145+
training_timeout_seconds: # optional max time (in seconds) for a single training run (-1 disables the timeout)
146146
147147
# Grid Search
148148
# if only 1 configuration is selected, any inner model selection will be skipped
@@ -192,12 +192,12 @@ explanation of each field as a comment:
192192
main_scorer: mlwiz.training.callback.metric.MulticlassAccuracy
193193
my_second_metric: mlwiz.training.callback.metric.ToyMetric
194194
195-
# Training engine
196-
engine:
197-
class_name: mlwiz.training.engine.TrainingEngine
198-
args:
199-
mixed_precision: False # set to True to enable torch AMP autocast (CUDA/CPU)
200-
mixed_precision_dtype: torch.float16 # torch.float16 | torch.bfloat16
195+
# Training engine
196+
engine:
197+
class_name: mlwiz.training.engine.TrainingEngine
198+
args:
199+
mixed_precision: False # set to True to enable torch AMP autocast (CUDA/CPU)
200+
mixed_precision_dtype: torch.float16 # torch.float16 | torch.bfloat16
201201
202202
# Gradient clipper (optional)
203203
gradient_clipper: null
@@ -244,6 +244,22 @@ Here we can define how many resources to allocate to parallelize different exper
244244
max_gpus: 2
245245
gpus_per_task: 0.5
246246
247+
For **Distributed Data Parallel (DDP)**, set ``gpus_per_task`` to an integer greater than 1.
248+
When ``device: cuda``, MLWiz automatically switches to DDP inside each Ray task.
249+
250+
.. code-block:: yaml
251+
252+
# one experiment uses 2 GPUs with DDP
253+
# with max_gpus: 4, Ray can run up to 2 such experiments in parallel
254+
device: cuda
255+
max_cpus: 24
256+
max_gpus: 4
257+
gpus_per_task: 2
258+
259+
MLWiz shards the training data with ``DistributedSampler`` and keeps a single set of
260+
experiment artifacts (rank 0 writes logs/checkpoints/plots). If a rank fails, check
261+
``ddp_rank_0.log``, ``ddp_rank_1.log``, ... inside the run folder.
262+
247263

248264

249265
Data Loading
@@ -271,26 +287,26 @@ our results:
271287

272288
.. code-block:: yaml
273289
274-
result_folder: RESULTS
275-
exp_name: mlp
276-
experiment: mlwiz.experiment.MLP
277-
model_selection_criteria:
278-
- metric: main_score
279-
direction: max
280-
evaluate_every: 3
281-
risk_assessment_training_runs: 3
282-
model_selection_training_runs: 2
283-
training_timeout_seconds: -1 # set to a positive value to enforce a per-run time budget
284-
285-
``higher_results_are_better`` is still supported as a legacy shortcut for a
286-
single ``main_score`` criterion, but it cannot be used together with
287-
``model_selection_criteria``.
288-
289-
By default MLWiz will run each training session until either the configured number of epochs is reached or the early
290-
stopper halts it. If you need to cap the wall-clock time of each run, set ``training_timeout_seconds`` to a positive
291-
value. The :class:`~mlwiz.training.engine.TrainingEngine` tracks the elapsed time (including previous attempts when
292-
resuming from checkpoints) and stops scheduling additional epochs once the limit is reached, logging the reason for the
293-
interruption. Keeping checkpointing enabled lets you safely resume from where the timeout was triggered.
290+
result_folder: RESULTS
291+
exp_name: mlp
292+
experiment: mlwiz.experiment.MLP
293+
model_selection_criteria:
294+
- metric: main_score
295+
direction: max
296+
evaluate_every: 3
297+
risk_assessment_training_runs: 3
298+
model_selection_training_runs: 2
299+
training_timeout_seconds: -1 # set to a positive value to enforce a per-run time budget
300+
301+
``higher_results_are_better`` is still supported as a legacy shortcut for a
302+
single ``main_score`` criterion, but it cannot be used together with
303+
``model_selection_criteria``.
304+
305+
By default MLWiz will run each training session until either the configured number of epochs is reached or the early
306+
stopper halts it. If you need to cap the wall-clock time of each run, set ``training_timeout_seconds`` to a positive
307+
value. The :class:`~mlwiz.training.engine.TrainingEngine` tracks the elapsed time (including previous attempts when
308+
resuming from checkpoints) and stops scheduling additional epochs once the limit is reached, logging the reason for the
309+
interruption. Keeping checkpointing enabled lets you safely resume from where the timeout was triggered.
294310

295311

296312
Grid Search
@@ -301,6 +317,7 @@ you can define lists associated to an hyper-parameter and all possible combinati
301317
nesting of these combinations for maximum flexibility.
302318

303319
There is one config file ``examples/MODEL_CONFIGS/config_MLP.yml`` that you can check to get a better idea.
320+
For a multi-GPU DDP setup, refer to ``examples/MODEL_CONFIGS/config_MLP_ddp.yml``.
304321

305322

306323
Random Search
@@ -332,7 +349,8 @@ or
332349

333350
.. code-block:: bash
334351
335-
mlwiz-exp --config-file examples/MODEL_CONFIGS/config_MLP.yml
352+
mlwiz-exp --config-file examples/MODEL_CONFIGS/config_MLP_ddp.yml
353+
336354
337355
338356
And we are up and running!
@@ -357,35 +375,35 @@ to you, please consider reading `Samy Bengio's lecture (Part 3) <https://bengio.
357375
Navigating the live progress UI
358376
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
359377

360-
The progress screen is interactive. Press ``:`` to open the small prompt in the bottom-right corner, type a command, and
361-
hit ``Enter`` to switch what is rendered without stopping the run. Useful commands:
362-
363-
- ``:`` (or ``:g`` / ``:global``): go back to the default overview with all progress bars.
364-
- ``:r`` (or ``:refresh``): redraw the currently selected view (handy if the terminal layout gets messy).
365-
- ``:<outer> <run>`` (e.g., ``:1 2``): focus the *risk assessment* run number ``run`` of outer fold ``outer`` (numbers start at 1).
366-
- ``:<outer> <inner> <config> <run>`` (e.g., ``:2 1 3 1``): focus a *model selection* run for a specific config inside an outer/inner fold pair.
367-
368-
Global overview (default view):
369-
370-
.. image:: _static/exp_gui.png
371-
:width: 600
372-
373-
If an identifier is invalid or the run has not produced updates yet, MLWiz will print a short hint and keep listening so
374-
you can try again.
375-
376-
You can also use the arrow keys:
377-
378-
- **left/right**: move across runs/configurations within the currently selected view.
379-
- **up/down**: toggle between the most recently visited model selection view and risk assessment view.
380-
381-
Focused run view (same as what you see when running with ``--debug``):
382-
383-
.. image:: _static/run_view.png
384-
:width: 600
385-
386-
To stop the computation, use ``CTRL-C`` to send a ``SIGINT`` signal, and consider using the command ``ray stop`` to stop
387-
all Ray processes. **Warning:** ``ray stop`` stops **all** ray processes you have launched, including those of other
388-
experiments in progress, if any.
378+
The progress screen is interactive. Press ``:`` to open the small prompt in the bottom-right corner, type a command, and
379+
hit ``Enter`` to switch what is rendered without stopping the run. Useful commands:
380+
381+
- ``:`` (or ``:g`` / ``:global``): go back to the default overview with all progress bars.
382+
- ``:r`` (or ``:refresh``): redraw the currently selected view (handy if the terminal layout gets messy).
383+
- ``:<outer> <run>`` (e.g., ``:1 2``): focus the *risk assessment* run number ``run`` of outer fold ``outer`` (numbers start at 1).
384+
- ``:<outer> <inner> <config> <run>`` (e.g., ``:2 1 3 1``): focus a *model selection* run for a specific config inside an outer/inner fold pair.
385+
386+
Global overview (default view):
387+
388+
.. image:: _static/exp_gui.png
389+
:width: 600
390+
391+
If an identifier is invalid or the run has not produced updates yet, MLWiz will print a short hint and keep listening so
392+
you can try again.
393+
394+
You can also use the arrow keys:
395+
396+
- **left/right**: move across runs/configurations within the currently selected view.
397+
- **up/down**: toggle between the most recently visited model selection view and risk assessment view.
398+
399+
Focused run view (same as what you see when running with ``--debug``):
400+
401+
.. image:: _static/run_view.png
402+
:width: 600
403+
404+
To stop the computation, use ``CTRL-C`` to send a ``SIGINT`` signal, and consider using the command ``ray stop`` to stop
405+
all Ray processes. **Warning:** ``ray stop`` stops **all** ray processes you have launched, including those of other
406+
experiments in progress, if any.
389407

390408
Useful Features to Know About
391409
------------------------------

mlwiz/experiment/experiment.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,13 +696,10 @@ def _run_valid_impl(
696696
(
697697
train_loss,
698698
train_score,
699-
_, # check the ordering is correct
700699
val_loss,
701700
val_score,
702701
_,
703702
_,
704-
_,
705-
_,
706703
) = training_engine.train(
707704
train_loader=train_loader,
708705
validation_loader=val_loader,
@@ -824,13 +821,10 @@ def _run_test_impl(
824821
(
825822
train_loss,
826823
train_score,
827-
_,
828824
val_loss,
829825
val_score,
830-
_,
831826
test_loss,
832827
test_score,
833-
_,
834828
) = training_engine.train(
835829
train_loader=train_loader,
836830
validation_loader=val_loader,

mlwiz/static.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676

7777
# STRING FORMATTING
7878
TENSORBOARD = "tensorboard"
79-
EMB_TUPLE_SUBSTR = "_embeddings_tuple"
8079
ATOMIC_SAVE_EXTENSION = ".part"
8180
CLASS_NAME = "class_name"
8281
ARGS = "args"

0 commit comments

Comments
 (0)