-
Notifications
You must be signed in to change notification settings - Fork 34.7k
🚨 TP dtensor API inference + training #47579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
244 commits
Select commit
Hold shift + click to select a range
799ac94
add distributed config
3outeille 22d4b52
Add native FSDP2 module and migrate FSDP imports (Phase A PR-2).
3outeille 4bfd1a6
linting
3outeille 9487bdd
unecessary
3outeille 588884e
copyright edit
3outeille 8cc48a0
revert
3outeille 672bbbe
add shard on read
3outeille 5bbc796
Merge branch 'main' into split/a-pr-1-distributed-config
3outeille d0cc6a7
jsut shard on read
3outeille 6fd7813
Merge branch 'split/a-pr-1-distributed-config' into split/a-pr-2-fsdp…
3outeille 47519d7
Merge branch 'main' into split/a-pr-3-dual-path-loading
3outeille 063e57b
cleaning
3outeille c06dc35
Merge branch 'split/a-pr-3-dual-path-loading' of https://github.com/h…
3outeille 9d2e86d
linting
3outeille 79457b3
fix
3outeille f3e8021
fix
3outeille acacae8
Merge branch 'split/a-pr-1-distributed-config' into split/a-pr-2-fsdp…
3outeille 54c1f4e
Merge branch 'main' into split/a-pr-1-distributed-config
3outeille d23986a
Merge branch 'main' into split/a-pr-3-dual-path-loading
3outeille f219c74
Merge branch 'split/a-pr-1-distributed-config' into split/a-pr-2-fsdp…
3outeille ea8243f
remove redundant test file
3outeille db31b04
Merge branch 'main' into split/a-pr-1-distributed-config
3outeille 4d840dc
Merge branch 'split/a-pr-1-distributed-config' into split/a-pr-2-fsdp…
3outeille c384fcd
Update src/transformers/distributed/fsdp.py
3outeille 9625816
avoid looping, just look at dict
3outeille 59bcec5
expand_fsdp returns reshard_targets, no_reshard_targets right away
3outeille ebf3585
better _resolve_tied_embed_lm_head_plan
3outeille e969325
cleaning
3outeille 2376965
ruff
3outeille d830114
Merge branch 'main' into split/a-pr-1-distributed-config
3outeille a44f81f
Merge branch 'split/a-pr-1-distributed-config' into split/a-pr-2-fsdp…
3outeille 0f62c45
more robust detection of embed and lm_head
3outeille 020f7d3
Merge branch 'split/a-pr-2-fsdp-module' of https://github.com/hugging…
3outeille 05d766f
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille da302ad
cleaning
3outeille dfc665c
ruff
3outeille 446fd6e
typo
3outeille 5aeaff7
cleaner
3outeille 819ff14
cleaner
3outeille 413d775
Merge branch 'main' into split/a-pr-1-distributed-config
3outeille 7bc3722
Merge branch 'split/a-pr-1-distributed-config' into split/a-pr-2-fsdp…
3outeille d6d8b51
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille f8f27ff
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille ce2f001
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille ec87fff
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 6e156fd
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 606df0a
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 3ee8a92
typo
3outeille 6bc43ae
Merge branch 'split/a-pr-3-dual-path-loading' of https://github.com/h…
3outeille c4aa4b7
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille c5ad67b
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 3c6c5f2
refactor dense path + apply_contiguous_shard
3outeille 74490d6
linting
3outeille db6c99e
cleaning
3outeille 04c124e
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 8f214ef
refactor _apply_strided_shard
3outeille ab34afb
better
3outeille c4bf166
refactor _slice_and_cat
3outeille be61c49
better comment
3outeille 75ad5b9
refactor moe dtensor shard ops
3outeille 91cd797
better comment
3outeille 68069de
comment
3outeille 83029ed
cleaning
3outeille 1f857df
linting
3outeille aa140ed
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 8b57aa4
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 7c11394
Add FSDP orchestration: mesh init, distribute-before-load, and DCP save.
3outeille 70544cd
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 17c6d40
Merge branch 'split/a-pr-3-dual-path-loading' into split/a-pr-4-fsdp-…
3outeille 00eb116
add fsdp plan to 2 models for now
3outeille be296dd
add tests fsdp mixin
3outeille 05900d6
linting
3outeille fc2423b
refactor test fsdp mixin
3outeille 5bbd820
test fsdp mixin cleaning
3outeille b6d0b67
remove fsdp policy in tests + trim down further
3outeille ea36123
test fsdp clean
3outeille bec4d23
restore test_modeling_utils
3outeille 8d3d329
linting
3outeille 6316ee1
start trim down stuff
3outeille 6e9004e
fix
3outeille 68df491
breaking: cleaning modeling_utils.py
3outeille 16b0b29
load path with fsdp (dtensor) and tp (old tp) is linked
3outeille e976a44
linting
3outeille a2fb155
add saving
3outeille 5f52f19
styling
3outeille 7f54301
fix tp ci
3outeille 99f79ac
add fsdp to ci
3outeille b451490
linting
3outeille 54ff4d1
pick one model only for this PR
3outeille 3399539
restore
3outeille 11cf79c
trigger fsdp ci
3outeille 5b7ac3e
doc cleaning + tp_size remove
3outeille 06b0c39
fix tp ci for ep
3outeille 7a94d77
edit doc
3outeille f3c742b
move distributed function to utils + guarding
3outeille 37df13e
linting
3outeille dd1000b
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 5c95559
expand_fsdp_plan iterate over modules
3outeille 00a11b6
Merge branch 'split/a-pr-2-fsdp-module' of https://github.com/hugging…
3outeille fd3d4b0
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 86875d2
Merge branch 'split/a-pr-3-dual-path-loading' into split/a-pr-4-fsdp-…
3outeille e4613e6
comment about tie embedding
3outeille c2b8451
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille d558f99
add comment tied embedding
3outeille aed1818
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 450579b
Merge branch 'split/a-pr-3-dual-path-loading' into split/a-pr-4-fsdp-…
3outeille 91260ba
add DistributedMixin
3outeille 1541674
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 9fd759d
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 84dd107
solve merge conflict
3outeille 9fae1b4
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille eb653bd
some cleaning
3outeille dcaa20a
Merge branch 'split/a-pr-3-dual-path-loading' of https://github.com/h…
3outeille d03499f
cleaning + comment
3outeille fb5533e
rename function for clarity
3outeille 7838dc6
Apply suggestion from @ArthurZucker
3outeille 877052b
doc
3outeille 59f666f
Merge branch 'split/a-pr-3-dual-path-loading' of https://github.com/h…
3outeille 17643a7
comment
3outeille 7bb152c
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 0b4d1e0
Merge branch 'main' into split/a-pr-2-fsdp-module
3outeille 101562d
Merge branch 'split/a-pr-2-fsdp-module' into split/a-pr-3-dual-path-l…
3outeille 99576ee
Merge branch 'split/a-pr-3-dual-path-loading' into split/a-pr-4-fsdp-…
3outeille 22215b7
linting
3outeille f6ed465
Merge branch 'split/a-pr-4-fsdp-orchestration' of https://github.com/…
3outeille 18d709c
refactor
3outeille 566ef6e
abstract to mixin
3outeille b632db3
typo
3outeille 0eec8c7
Add FSDP plans to all models from distributed branch.
3outeille a1f4b71
fsdp plans
3outeille a07e5bf
add fsdp plans
3outeille 0dfe224
linting
3outeille e5a6535
linting
3outeille e764ceb
Add distributed runtime utils and DistributedMixin (FSDP orchestratio…
3outeille 61362b7
Wire DistributedConfig through from_pretrained and save_pretrained (F…
3outeille eb34d37
Add FSDP CI and end-to-end FSDP tests (FSDP orchestration 3/3).
3outeille b866f00
addd ep_plan
3outeille 3da6fb9
Merge branch 'split/a-pr-4-1-distributed-runtime' into split/a-pr-4-2…
3outeille ca8d037
Merge branch 'split/a-pr-4-2-orchestration' into split/a-pr-4-3-fsdp-…
3outeille b3f4538
restore validate module
3outeille b1fb1b9
Wire DistributedConfig through from_pretrained and save_pretrained.
3outeille 1bf32cc
revert
3outeille 1620c0f
Merge branch 'split/a-pr-4-1-distributed-runtime' into split/a-pr-4-2…
3outeille fe0dcf7
Merge branch 'split/a-pr-4-2-orchestration' into split/a-pr-4-3-fsdp-…
3outeille e52fda3
inline distribute_model
3outeille 71dde8a
revert
3outeille 4e23dbf
remove saving/loading
3outeille 5742a2e
leaner mixin
3outeille 5c81035
downgrade torch version guarding
3outeille 004354f
remove
3outeille 6d03414
linting
3outeille 450987f
Merge branch 'split/a-pr-4-1-distributed-runtime' into split/a-pr-4-3…
3outeille 47d85ad
revert
3outeille c577f33
Merge branch 'split/a-pr-4-2-fsdp-tests-ci' of https://github.com/hug…
3outeille b319d6a
revert
3outeille eb9a081
post_init() parallel plan move to mixin
3outeille d5358f3
Merge branch 'split/a-pr-4-1-distributed-runtime' into split/a-pr-4-2…
3outeille 9a783c8
revert tp mixin
3outeille 0448e72
Merge branch 'split/a-pr-4-1-distributed-runtime' into split/a-pr-4-2…
3outeille 259bff4
add save/load
3outeille b15b63e
Merge branch 'main' into split/a-pr-4-1-distributed-runtime
3outeille 17d611b
Merge branch 'main' into split/a-pr-4-1-distributed-runtime
3outeille 7fe841b
Merge branch 'main' into split/a-pr-4-1-distributed-runtime
3outeille 5f9b5ab
Merge branch 'split/a-pr-4-1-distributed-runtime' into split/a-pr-4-2…
3outeille b95be32
Merge branch 'main' into split/a-pr-4-2-fsdp-tests-ci
3outeille d625757
only FSDP save/load for now
3outeille 9e810e4
Merge branch 'split/a-pr-4-2-fsdp-tests-ci' of https://github.com/hug…
3outeille 049b89c
revert
3outeille a03f35a
Merge remote-tracking branch 'origin/split/a-pr-4-2-fsdp-tests-ci' in…
3outeille 6b35d0e
refactor
3outeille 862b428
Merge branch 'split/a-pr-4-2-fsdp-tests-ci' into split/a-pr-5-fsdp-plans
3outeille e503205
modular
3outeille c7fa843
Merge branch 'split/a-pr-5-fsdp-plans' of https://github.com/huggingf…
3outeille 047bd41
Merge branch 'main' into split/a-pr-4-2-fsdp-tests-ci
3outeille 8c96054
Merge branch 'main' into split/a-pr-4-2-fsdp-tests-ci
3outeille a1b0d77
Merge branch 'split/a-pr-4-2-fsdp-tests-ci' into split/a-pr-5-fsdp-plans
3outeille c364a54
Merge branch 'main' into split/a-pr-5-fsdp-plans
3outeille 36ca137
ea
3outeille 2f87b7d
Merge branch 'main' into split/a-pr-5-fsdp-plans
3outeille a171a19
begin migration TP
3outeille 71255bf
clean up
3outeille d44d5db
Merge branch 'main' into split/a-pr-5-fsdp-plans
3outeille 507a3c7
add it to pretrained model
3outeille 258ab19
linting
3outeille 70de295
fix the test by moving in init class the fsdp plan instead of post init
3outeille 830f0e4
edit
3outeille 0ddc172
replace everything
3outeille 7193907
Merge branch 'split/a-pr-5-fsdp-plans' into distributed_guarding
3outeille 4cb403f
Merge branch 'distributed_guarding' into split/b-pr-0-dual-path-tp
3outeille ad7248f
begin migration TP
3outeille 1dcd5d2
clean up
3outeille 2cccb89
revert merge conflict
3outeille 4098e00
local params for forward
3outeille ed5c136
merged
3outeille b972782
cleaning
3outeille 2469b2b
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille c416695
migration from integration.tensor_parallel to distributed.tensor_pa…
3outeille 68e932d
xMerge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/t…
3outeille 673188f
revert models
3outeille d2ecb9b
revert
3outeille 7aacfdf
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 5f392ff
fix
3outeille a2aaec7
breaking: cleaner way to_local for quantize weight(almost done need t…
3outeille 2119865
fix all tests
3outeille 48bf5b5
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 911ac80
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 42edef6
TP dtensor handle natively the to_local() for deepgem + fp8 (#47634)
3outeille dec0187
bench: dtensor vs legacy TP
3outeille c1bc2ca
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille d31aa8c
bench: dtensor vs legacy TP (#47728)
3outeille 632724b
Merge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/tr…
3outeille 610f3ff
remove helper script
3outeille c10dd03
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille d0cdd9c
remove dead code in mxfp4
3outeille 02077ae
Merge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/tr…
3outeille 57cf762
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 6c4063d
remove old TP
3outeille 078f128
Merge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/tr…
3outeille 8c66c74
cleaning
3outeille 8b5f362
cleaning
3outeille 8e26b06
claening
3outeille 7febb1b
add test_shard_tensor_shape_consistency
3outeille 1333432
cleaning
3outeille 7eaf787
small fix
3outeille e62fff9
typo
3outeille 2af1175
comment
3outeille 5e450f3
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille a29469e
rename colwise_gather_output to colwise_rep
3outeille 637e37a
Merge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/tr…
3outeille b41ddc9
keep tp import to avoid breaking chnges
3outeille 488b801
remove async_op=True for redistribute
3outeille 1230989
linting
3outeille 1fc95b3
renaming MoeExpertsParallel class
3outeille 351a4cd
ep router doc
3outeille 2fd62de
mlinter
3outeille ddced0c
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 2a37985
add todo
3outeille 4eb3126
Merge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/tr…
3outeille 78f88a2
fix
3outeille d88b9b5
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille e2644a6
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 16dcef7
Merge branch 'main' into split/b-pr-0-dual-path-tp
3outeille 47921ca
remove unused keys from global_mapping to avoid BC
3outeille ff7f904
Merge branch 'split/b-pr-0-dual-path-tp' of github.com:huggingface/tr…
3outeille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,14 +33,12 @@ | |
| from .distributed.sharding_utils import DtensorShardOperation, _dtensor_from_local_like | ||
| from .distributed.utils import is_dtensor | ||
| from .integrations.accelerate import get_device, offload_weight | ||
| from .integrations.tensor_parallel import ALL_PARALLEL_STYLES | ||
| from .utils import is_env_variable_true | ||
| from .utils.loading_report import LoadStateDictInfo | ||
| from .utils.logging import get_logger, tqdm | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .integrations.tensor_parallel import TensorParallelLayer | ||
| from .modeling_utils import LoadStateDictConfig, PreTrainedModel | ||
| from .quantizers import HfQuantizer | ||
|
|
||
|
|
@@ -1232,9 +1230,9 @@ def spawn_materialize( | |
| ) -> Future | Callable: | ||
| """Materialize (and optionally shard) a tensor, asynchronously if a thread pool is provided. | ||
|
|
||
| When ``sharding_op`` is given the tensor is sharded (DTensor placement or legacy TP plan); | ||
| otherwise it is simply copied to *device*/*dtype*. Without a thread pool a deferred | ||
| callable is returned instead of a Future. | ||
| When ``sharding_op`` is given the tensor is sharded according to its DTensor placements; | ||
| otherwise it is simply copied to *device*/*dtype*. Without a thread pool a deferred callable | ||
| is returned instead of a Future. | ||
| """ | ||
|
|
||
| def _job(): | ||
|
|
@@ -1319,7 +1317,6 @@ def set_param_for_module( | |
| target_name: str, | ||
| param_value: torch.Tensor, | ||
| loading_info: LoadStateDictInfo, | ||
| distributed_operation: TensorParallelLayer | None, | ||
| hf_quantizer: HfQuantizer, | ||
| ): | ||
| module_path, _, param_name = target_name.rpartition(".") | ||
|
|
@@ -1341,26 +1338,21 @@ def set_param_for_module( | |
| # Remove from missing keys (it's either mismatched, or all good) | ||
| loading_info.missing_keys.discard(target_name) | ||
|
|
||
| # Determine expected shape: for TP/Dtensor, use sharded shape; otherwise, use full shape | ||
| if distributed_operation is not None: | ||
| expected_shape = torch.Size(distributed_operation.get_expected_sharded_shape(ref.shape)) | ||
| elif is_dtensor(ref): | ||
| expected_shape = ref._local_tensor.shape | ||
| else: | ||
| expected_shape = ref.shape | ||
| # For DTensor parameters, compare against the local shard loaded on this rank. | ||
| expected_shape = ref._local_tensor.shape if is_dtensor(ref) else ref.shape | ||
|
|
||
| if ref is not None and param_value.shape != expected_shape and hf_quantizer is None: | ||
| loading_info.mismatched_keys.add((target_name, param_value.shape, expected_shape)) | ||
| else: | ||
| if is_dtensor(ref): | ||
| local_param = param_value.detach() if isinstance(param_value, torch.nn.Parameter) else param_value | ||
| dtensor_param = _dtensor_from_local_like(local_param, ref) | ||
| param_value = torch.nn.Parameter(dtensor_param, requires_grad=ref.requires_grad) | ||
| param_value = torch.nn.Parameter( | ||
| dtensor_param, requires_grad=ref.requires_grad and dtensor_param.is_floating_point() | ||
| ) | ||
| # super important otherwise _init_weight will re-init the param | ||
| param_value._is_hf_initialized = True | ||
| setattr(module_obj, param_name, param_value) | ||
| if distributed_operation is not None: | ||
| distributed_operation.update_module_attributes(module_obj) | ||
|
|
||
|
|
||
| def offload_and_maybe_resave_param( | ||
|
|
@@ -1466,7 +1458,6 @@ def convert_and_load_state_dict_in_model( | |
| model: PreTrainedModel, | ||
| state_dict: dict[str, Any], | ||
| load_config: LoadStateDictConfig, | ||
| tp_plan: dict[str, str] | None, | ||
| disk_offload_index: dict | None = None, | ||
| ): | ||
| r""" | ||
|
|
@@ -1556,11 +1547,9 @@ def convert_and_load_state_dict_in_model( | |
|
|
||
| """ | ||
| base_model_prefix = model.base_model_prefix | ||
| tp_plan = tp_plan or {} | ||
| device_map = load_config.device_map or {"": "cpu"} | ||
| hf_quantizer = load_config.hf_quantizer | ||
| dtype = load_config.dtype | ||
| device_mesh = load_config.device_mesh | ||
| disk_offload_folder = load_config.disk_offload_folder | ||
| offload_buffers = load_config.offload_buffers | ||
| dtype_plan = load_config.dtype_plan or {} | ||
|
|
@@ -1595,10 +1584,6 @@ def convert_and_load_state_dict_in_model( | |
| converters = [entry for entry in weight_mapping if isinstance(entry, WeightConverter)] | ||
| param_name_to_load: dict[str, WeightRenaming | WeightConverter] = {} | ||
|
|
||
| # build '(?P<g0>.*.*\\.block_sparse_moe\\..*)' and group to source {'g0': '*.block_sparse_moe.'} | ||
| # and target to source {'g0': '*.mlp.'}. This allows us to quickly find which pattern matched. | ||
| if tp_plan != {}: | ||
| tp_plan_alt, tp_plan_by_group_name, _ = build_glob_alternation(list(tp_plan.keys())) | ||
| if dtype_plan != {}: | ||
| dtype_policy_alt, dtype_policy_by_group_name, _ = build_glob_alternation(list(dtype_plan.keys())) | ||
|
|
||
|
|
@@ -1673,23 +1658,13 @@ def convert_and_load_state_dict_in_model( | |
| else None | ||
| ) | ||
|
|
||
| # 4. Handle TP/Dtensor sharding or device_map placement | ||
| # 4. Handle DTensor sharding or device_map placement | ||
| param_device = get_device(device_map, renamed_key, valid_torch_device=True) | ||
| sharding_op = None | ||
| materialize_device = param_device | ||
|
|
||
| if is_dtensor(empty_param): | ||
| sharding_op = DtensorShardOperation(empty_param) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everything happens in here now?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it will load only the slice of the safetensors based on dtensor metadata placements |
||
| elif device_mesh and tp_plan: | ||
| if matched_tp_pattern := tp_plan_alt.search(renamed_key): | ||
| matched_tp_pattern = tp_plan_by_group_name[matched_tp_pattern.lastgroup] | ||
| if getattr(mapping, "distributed_operation", None) is None: | ||
| tp_layer = ALL_PARALLEL_STYLES[model.tp_plan[matched_tp_pattern]].__class__ | ||
| mapping.distributed_operation = tp_layer( | ||
| device_mesh=device_mesh, rank=device_mesh.get_local_rank(), empty_param=empty_param.clone() | ||
| ) | ||
| sharding_op = mapping.distributed_operation | ||
| materialize_device = device_map[""] | ||
|
|
||
| future_or_tensor = spawn_materialize( | ||
| thread_pool, | ||
|
|
@@ -1732,7 +1707,6 @@ def convert_and_load_state_dict_in_model( | |
| target_name, | ||
| param, | ||
| loading_info, | ||
| mapping.distributed_operation, | ||
| hf_quantizer, | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed as DTensor carries global/local shape metadata + special attributes such as
num_expertsare updated byMoEParamShard.shard_param().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is marvellous