Repository navigation
refactor: remove redundant apply_optimizer_in_backward in sharding.py - #330
Conversation
Greptile SummaryThis PR removes the redundant Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as make_optimizer_and_shard
participant DMP as apply_dmp
participant Sharder as DynamicEmb Sharders
participant DMP_Module as DistributedModelParallel
Caller->>DMP: call apply_dmp(model, ...)
Note over DMP: Build fused_params dict<br/>(optimizer, lr, beta1, beta2, eps, ...)
DMP->>DMP: Enumerate TORCHREC_TYPES modules<br/>Collect eb_configs
Note over DMP: ❌ REMOVED (was here):<br/>apply_optimizer_in_backward(sparse_opt_cls, [param], ...)<br/>for each param in TORCHREC_TYPES modules
DMP->>Sharder: Create DynamicEmbeddingBagCollectionSharder(fused_params=fused_params)
DMP->>Sharder: Create DynamicEmbeddingCollectionSharder(fused_params=fused_params)
DMP->>DMP_Module: DistributedModelParallel(module, sharders, plan, ...)
Note over Sharder,DMP_Module: fused_params is the SOLE optimizer config path.<br/>Sharders embed optimizer settings into FBGEMM kernels.
DMP->>DMP: Assert non_fused_sparse_params == 0<br/>(sanity check — fused path covers all params)
DMP-->>Caller: return sharded model
Last reviewed commit: "refactor: remove red..." |
|
@JacoCheung could you help review? If it's safe you can merge it. |
|
Added CI. Let's merge if ci passes. @shijieliu |
|
Could you help re-format the code? @gameofdimension . |
I notice the issue author hasn't responded yet. I'd be happy to re-format Could you let me know which formatter or style guide I should follow? |
|
Hi, I'll merge it first and format it later. Thanks for your contribution. @gameofdimension @ShaobinChen-AH |
Description
Checklist
Summary
Remove the redundant
apply_optimizer_in_backwardcall insharding.py.ContextAs discussed in #322, both
apply_optimizer_in_backwardandfused_paramsare used to add optimizer for embeddings. However,fused_paramsalready has the capability to handle optimizer parameters and absorbs the params thatapply_optimizer_in_backwardprovides.Since
apply_optimizer_in_backwardhas higher priority thanfused_paramsbut serves the same purpose, it is redundant in this context.Changes- Remove
apply_optimizer_in_backwardcall fromexamples/commons/distributed/sharding.py(lines 236-272)- Keepfused_paramsas the sole optimizer configuration methodTesting- [ ] Verified no syntax errors- [ ] Ran related tests (if applicable)
Closes #322
CI