Skip to content

Commit faa0c3d

Browse files
[feat] remove patch_dynamicemb_eval_model (#286)
1 parent 77daba0 commit faa0c3d

7 files changed

Lines changed: 6 additions & 35 deletions

File tree

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# -- Project information -----------------------------------------------------
3030

3131
project = "tzrec"
32-
copyright = "2024, EasyRec Team"
32+
copyright = "2024-2025, EasyRec Team"
3333
author = "EasyRec Team"
3434

3535
version_file = "../../tzrec/version.py"

docs/source/feature/dynamicemb.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DynamicEmbedding 是特征零Hash冲突Id化的一种方式,它相比设置`ha
55
注:目前使用DynamicEmbedding还处于实验阶段,配置和接口都可能调整,暂不包含在官方提供的镜像环境中,使用前需要额外安装如下whl包
66

77
```bash
8-
pip install https://tzrec.oss-accelerate.aliyuncs.com/third_party/dynamicemb/dynamicemb-0.0.1%2B20250929.6a3aeab-cp311-cp311-linux_x86_64.whl
8+
pip install https://tzrec.oss-accelerate.aliyuncs.com/third_party/dynamicemb/dynamicemb-0.0.1%2B20251013.60a6ddf-cp311-cp311-linux_x86_64.whl
99
```
1010

1111
以id_feature的配置为例,DynamicEmbedding 只需在id_feature新增一个dynamicemb的配置字段

requirements/gpu.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dynamicemb @ https://tzrec.oss-accelerate.aliyuncs.com/third_party/dynamicemb/dynamicemb-0.0.1%2B20250929.6a3aeab-cp311-cp311-linux_x86_64.whl ; python_version=="3.11"
1+
dynamicemb @ https://tzrec.oss-accelerate.aliyuncs.com/third_party/dynamicemb/dynamicemb-0.0.1%2B20251013.60a6ddf-cp311-cp311-linux_x86_64.whl ; python_version=="3.11"
22
faiss_gpu_cu12 @ https://tzrec.oss-accelerate.aliyuncs.com/third_party/faiss/faiss_gpu_cu12-1.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.10"
33
faiss_gpu_cu12 @ https://tzrec.oss-accelerate.aliyuncs.com/third_party/faiss/faiss_gpu_cu12-1.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.11"
44
faiss_gpu_cu12 @ https://tzrec.oss-cn-beijing.aliyuncs.com/third_party/faiss/faiss_gpu_cu12-1.11.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl ; python_version=="3.12"

tzrec/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
from tzrec.protos.model_pb2 import ModelConfig
7575
from tzrec.protos.pipeline_pb2 import EasyRecConfig
7676
from tzrec.protos.train_pb2 import TrainConfig
77-
from tzrec.utils import checkpoint_util, config_util, dynamicemb_util
77+
from tzrec.utils import checkpoint_util, config_util
7878
from tzrec.utils.dist_util import (
7979
DistributedModelParallel,
8080
create_train_pipeline,
@@ -835,8 +835,6 @@ def evaluate(
835835
model, device=device, mixed_precision=train_config.mixed_precision
836836
)
837837

838-
# TODO: remove it when DynamicEmbedding support eval without optimizer
839-
dynamicemb_util._patch_dynamicemb_eval_model(model, pipeline_config.train_config)
840838
planner = create_planner(
841839
device=device,
842840
# pyre-ignore [16]

tzrec/utils/checkpoint_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def restore_model(
238238
os.path.join(checkpoint_dir, "dynamicemb"),
239239
model,
240240
table_names=meta.get("dynamicemb_load_table_names", None),
241-
optim=meta.get("dynamicemb_load_optim", True),
241+
optim=meta.get("dynamicemb_load_optim", optimizer is not None),
242242
)
243243
logger.info(f"{os.environ.get('RANK', 0)} restore dynamic embedding finished.")
244244

tzrec/utils/dynamicemb_util.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@
4444
ShardMetadata,
4545
)
4646
from torchrec.modules.embedding_configs import BaseEmbeddingConfig, DataType
47-
from torchrec.optim.apply_optimizer_in_backward import apply_optimizer_in_backward
48-
from torchrec.optim.optimizers import SGD
4947

50-
from tzrec.optim import optimizer_builder
5148
from tzrec.protos import feature_pb2
52-
from tzrec.protos.train_pb2 import TrainConfig
5349

5450
has_dynamicemb = False
5551
try:
@@ -205,29 +201,6 @@ def build_dynamicemb_constraints(
205201
return constraints
206202

207203

208-
def _patch_dynamicemb_eval_model(model: nn.Module, train_config: TrainConfig) -> None:
209-
"""Patch model with optimizer when eval.
210-
211-
because DynamicEmbedding Eval need optimizer now.
212-
"""
213-
if has_dynamicemb:
214-
with_dynamicemb_feature = False
215-
for feature in model.model._features:
216-
if hasattr(feature.config, "dynamicemb") and feature.config.HasField(
217-
"dynamicemb"
218-
):
219-
with_dynamicemb_feature = True
220-
break
221-
if with_dynamicemb_feature:
222-
sparse_optim_cls, _ = optimizer_builder.create_sparse_optimizer(
223-
train_config.sparse_optimizer
224-
)
225-
trainable_params, frozen_params = model.model.sparse_parameters()
226-
apply_optimizer_in_backward(sparse_optim_cls, trainable_params, {"lr": 0.0})
227-
if len(frozen_params) > 0:
228-
apply_optimizer_in_backward(SGD, frozen_params, {"lr": 0.0})
229-
230-
231204
if has_dynamicemb:
232205
enumerators.GUARDED_COMPUTE_KERNELS.add(EmbeddingComputeKernel.CUSTOMIZED_KERNEL)
233206

tzrec/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12-
__version__ = "0.9.2"
12+
__version__ = "0.9.3"

0 commit comments

Comments
 (0)