Skip to content

add distributed config - #46705

Merged
3outeille merged 9 commits into
mainfrom
split/a-pr-1-distributed-config
Jun 24, 2026
Merged

add distributed config#46705
3outeille merged 9 commits into
mainfrom
split/a-pr-1-distributed-config

Conversation

@3outeille

Copy link
Copy Markdown
Member

No description provided.

@3outeille 3outeille closed this Jun 17, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@3outeille 3outeille reopened this Jun 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46705&sha=799ac9

@github-actions

Copy link
Copy Markdown
Contributor

CI Dashboard: View test results in Grafana

@3outeille 3outeille mentioned this pull request Jun 17, 2026
5 tasks
@3outeille
3outeille requested a review from ArthurZucker June 23, 2026 04:42

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would remove the test here imo

# easily available
self._tp_plan, self._ep_plan, self._pp_plan = {}, {}, {}
# easily available.
self._tp_plan, self._ep_plan, self._pp_plan, self._fsdp_plan = {}, {}, {}, {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't you want to add the mixin in this PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I prefer to delay it to another PR once more thing have been merged. This way, it will be easier to know what will be abstracted away in the DistributedMixin once everything is there

Comment thread tests/test_distributed_config.py Outdated
@@ -0,0 +1,97 @@
import json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

missing licence

Comment thread tests/test_distributed_config.py Outdated
Comment on lines +7 to +84
class TestDistributedConfig:
def test_2d_parallelism(self):
dc = DistributedConfig(tp_size=2, fsdp_size=2)
assert dc.tp_size == 2
assert dc.fsdp_size == 2
assert dc.tp_plan is None
assert dc.fsdp_cpu_offload is False
assert dc.fsdp_mixed_precision is False

def test_tp_only_defaults_fsdp_to_1(self):
dc = DistributedConfig(tp_size=4)
assert dc.tp_size == 4
assert dc.fsdp_size == 1
assert dc.tp_plan is None

def test_fsdp_only_defaults_tp_to_1(self):
dc = DistributedConfig(fsdp_size=4)
assert dc.tp_size == 1
assert dc.fsdp_size == 4
assert dc.fsdp_cpu_offload is False
assert dc.fsdp_mixed_precision is False
assert dc.tp_plan is None

def test_empty_config(self):
dc = DistributedConfig()
assert dc.tp_size is None
assert dc.fsdp_size is None
assert dc.tp_plan is None
assert dc.fsdp_cpu_offload is False
assert dc.fsdp_mixed_precision is False

def test_from_dict(self):
dc = DistributedConfig.from_dict({"tp_size": 2, "fsdp_size": 4})
assert dc.tp_size == 2
assert dc.fsdp_size == 4
assert dc.tp_plan is None

def test_from_dict_ignores_unknown_keys(self):
dc = DistributedConfig.from_dict({"tp_size": 2, "unknown_key": 42})
assert dc.tp_size == 2
assert not hasattr(dc, "unknown_key")

def test_from_dict_kwargs_override(self):
dc = DistributedConfig.from_dict({"tp_size": 2}, tp_size=8)
assert dc.tp_size == 8

def test_to_dict(self):
dc = DistributedConfig(tp_size=2, fsdp_size=4)
d = dc.to_dict()
assert d == {
"tp_size": 2,
"tp_plan": None,
"enable_sequence_parallel": False,
"enable_expert_parallel": False,
"fsdp_size": 4,
"fsdp_cpu_offload": False,
"fsdp_mixed_precision": False,
}

def test_to_dict_is_a_copy(self):
dc = DistributedConfig(tp_plan={"layer": "colwise"})
d = dc.to_dict()
d["tp_plan"]["layer"] = "rowwise"
assert dc.tp_plan["layer"] == "colwise"

def test_to_json_string(self):
dc = DistributedConfig(tp_size=2, fsdp_size=2)
s = dc.to_json_string()
parsed = json.loads(s)
assert parsed["tp_size"] == 2
assert parsed["fsdp_size"] == 2

def test_to_json_file(self):
dc = DistributedConfig(tp_size=4)
with tempfile.NamedTemporaryFile(mode="r", suffix=".json", delete=False) as f:
dc.to_json_file(f.name)
f.seek(0)
parsed = json.load(f)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't think we need such granularity!

@3outeille
3outeille requested a review from ArthurZucker June 24, 2026 10:20
@3outeille
3outeille enabled auto-merge June 24, 2026 10:45
@3outeille
3outeille disabled auto-merge June 24, 2026 13:55
@3outeille
3outeille enabled auto-merge June 24, 2026 14:20
@3outeille
3outeille added this pull request to the merge queue Jun 24, 2026
Merged via the queue into main with commit 2e2855f Jun 24, 2026
101 checks passed
@3outeille
3outeille deleted the split/a-pr-1-distributed-config branch June 24, 2026 14:47
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
* add distributed config

* fix

* fix

* remove redundant test file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants