Skip to content

refactor: use a common DatasetConfig class - #1712

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
lkhphuc:dataconf
Sep 16, 2025
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
lkhphuc:dataconf

Conversation

@lkhphuc

@lkhphuc lkhphuc commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

As suggested in the comment here for PR #1615 , I refactored all the dataset config instance to a common one in torchtitan/datasets/__init__.py, with a common name sample_processor.
Doing it here to make it easier to review and limit scope of the other PR.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 15, 2025

@tianyu-l tianyu-l left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Please fix lint.

@fegin fegin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one comment, please fix it.

Comment thread torchtitan/datasets/__init__.py Resolved
@lkhphuc

lkhphuc commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

Thanks. fixed lint and added `all``.

@tianyu-l
tianyu-l merged commit be2c83d into pytorch:main Sep 16, 2025
tianyu-l pushed a commit that referenced this pull request Sep 23, 2025
…on (#1730)

This PR resolves the `datasets` import error that were introduced in
#1712. The error causes the following error message:
```Traceback (most recent call last):
  File "./torchtitan/train.py", line 16, in <module>
    import torchtitan.protocols.train_spec as train_spec_module
  File "./torchtitan/__init__.py", line 12, in <module>
    import torchtitan.experiments  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./torchtitan/experiments/__init__.py", line 7, in <module>
    import torchtitan.experiments.llama4  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./torchtitan/experiments/llama4/__init__.py", line 11, in <module>
    from torchtitan.datasets.hf_datasets import build_hf_dataloader
  File "./torchtitan/datasets/hf_datasets.py", line 12, in <module>
    from datasets import Dataset, load_dataset
ImportError: cannot import name 'Dataset' from 'datasets' (./torchtitan/datasets/__init__.py)
```

Why is this happening? It is because #1712 added an `__init__.py` file
to the `datasets` folder. On the surface the PR looks fine, however, it
causes a collision with HF datasets Python package called `datasets`. So
when we try to import the `Dataset` class, we actually want the HF
datasets package and not the local `datasets` folder. This, in turn,
causes an import error. The solution is simple, change the `__init__.py`
name to something else, in our case I changed it to `common.py` as I
found this name most fitting.
@lkhphuc
lkhphuc deleted the dataconf branch October 14, 2025 10:58
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
As suggested in the comment
[here](pytorch#1615 (comment))
for PR pytorch#1615 , I refactored all the dataset config instance to a common
one in `torchtitan/datasets/__init__.py`, with a common name
`sample_processor`.
Doing it here to make it easier to review and limit scope of the other
PR.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
…on (pytorch#1730)

This PR resolves the `datasets` import error that were introduced in
pytorch#1712. The error causes the following error message:
```Traceback (most recent call last):
  File "./torchtitan/train.py", line 16, in <module>
    import torchtitan.protocols.train_spec as train_spec_module
  File "./torchtitan/__init__.py", line 12, in <module>
    import torchtitan.experiments  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./torchtitan/experiments/__init__.py", line 7, in <module>
    import torchtitan.experiments.llama4  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./torchtitan/experiments/llama4/__init__.py", line 11, in <module>
    from torchtitan.datasets.hf_datasets import build_hf_dataloader
  File "./torchtitan/datasets/hf_datasets.py", line 12, in <module>
    from datasets import Dataset, load_dataset
ImportError: cannot import name 'Dataset' from 'datasets' (./torchtitan/datasets/__init__.py)
```

Why is this happening? It is because pytorch#1712 added an `__init__.py` file
to the `datasets` folder. On the surface the PR looks fine, however, it
causes a collision with HF datasets Python package called `datasets`. So
when we try to import the `Dataset` class, we actually want the HF
datasets package and not the local `datasets` folder. This, in turn,
causes an import error. The solution is simple, change the `__init__.py`
name to something else, in our case I changed it to `common.py` as I
found this name most fitting.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
As suggested in the comment
[here](pytorch#1615 (comment))
for PR pytorch#1615 , I refactored all the dataset config instance to a common
one in `torchtitan/datasets/__init__.py`, with a common name
`sample_processor`.
Doing it here to make it easier to review and limit scope of the other
PR.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
…on (pytorch#1730)

This PR resolves the `datasets` import error that were introduced in
pytorch#1712. The error causes the following error message:
```Traceback (most recent call last):
  File "./torchtitan/train.py", line 16, in <module>
    import torchtitan.protocols.train_spec as train_spec_module
  File "./torchtitan/__init__.py", line 12, in <module>
    import torchtitan.experiments  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./torchtitan/experiments/__init__.py", line 7, in <module>
    import torchtitan.experiments.llama4  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./torchtitan/experiments/llama4/__init__.py", line 11, in <module>
    from torchtitan.datasets.hf_datasets import build_hf_dataloader
  File "./torchtitan/datasets/hf_datasets.py", line 12, in <module>
    from datasets import Dataset, load_dataset
ImportError: cannot import name 'Dataset' from 'datasets' (./torchtitan/datasets/__init__.py)
```

Why is this happening? It is because pytorch#1712 added an `__init__.py` file
to the `datasets` folder. On the surface the PR looks fine, however, it
causes a collision with HF datasets Python package called `datasets`. So
when we try to import the `Dataset` class, we actually want the HF
datasets package and not the local `datasets` folder. This, in turn,
causes an import error. The solution is simple, change the `__init__.py`
name to something else, in our case I changed it to `common.py` as I
found this name most fitting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants