Skip to content

Commit c4217d7

Browse files
authored
Merge pull request #465 from Modalities/feat/weighted-combined-dataset
feat: torch-free dataloader utilities for CPU-only tooling
2 parents 8b61a0e + a0ba73c commit c4217d7

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎CHANGELOG_DEV.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,17 @@ This PR improves training monitoring and logging across runs besides some other
217217
* Add tutorials on Einsum Transformer (Example model integration) and profiling
218218

219219
**Breaking Changes**
220-
* experiments_root_path is now exposed on an API level
220+
* experiments_root_path is now exposed on an API level
221+
222+
## PR #XXX Torch-free dataloader utilities for CPU-only tooling
223+
224+
**`TokenizerInstantiationModel`.** Lets a tool reuse a packing config for its tokenizer without
225+
also having to satisfy that config's settings, which name a specific source file the tool has no
226+
interest in.
227+
228+
**`get_logger` no longer requires torch.** The `import torch` in `utils/logger_utils.py` is only
229+
there for the rank prefix, but it is the reason `dataloader/create_index.py` -- and therefore
230+
`IndexGenerator` -- could not be imported without torch. Since modalities declares torch in its
231+
`cpu`/`cu12x` extras rather than as a base dependency, that made CPU-only data-preprocessing
232+
tooling install a multi-gigabyte wheel it never called. The import is now guarded and the rank
233+
prefix is simply omitted when torch is absent; behaviour with torch installed is unchanged.

‎src/modalities/config/instantiation_models.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ class PackedDatasetSettings(BaseModel):
223223
settings: PackedDatasetSettings
224224

225225

226+
class TokenizerInstantiationModel(BaseModel):
227+
"""Builds only the tokenizer of a config.
228+
229+
Lets a tool reuse a packing config for its tokenizer without also having to satisfy
230+
that config's settings, which name a specific source file the tool has no interest
231+
in. Building from the packing config is what guarantees the same tokenizer is used
232+
for measuring token estimates and for the packing those estimates predict.
233+
"""
234+
235+
tokenizer: PydanticTokenizerIFType
236+
237+
226238
class TextGenerationInstantiationModel(BaseModel):
227239
class TextGenerationSettings(BaseModel):
228240
model_path: FilePath

‎src/modalities/utils/logger_utils.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import logging
22

3-
import torch
3+
try:
4+
# Only needed for the rank prefix. Guarded so that CPU-only tooling -- data
5+
# preprocessing in particular -- can import the dataloader utilities without
6+
# pulling in torch, which modalities declares in its cpu/cu12x extras rather
7+
# than as a base dependency.
8+
import torch
9+
except ImportError: # pragma: no cover - exercised only in torch-free installs
10+
torch = None
411

512

613
def get_logger(name: str = "main") -> logging.Logger:
714
rank_info = ""
815

9-
if torch.distributed.is_initialized():
16+
if torch is not None and torch.distributed.is_initialized():
1017
rank_info = f"[RANK {torch.distributed.get_rank()}] "
1118

1219
logger = logging.getLogger(name)

0 commit comments

Comments
 (0)