HugeCTR 开源项目教程
项目介绍
HugeCTR 是一个专为点击率(CTR)估计训练设计的高效 GPU 框架。它旨在加速大规模深度学习模型的训练和推理,特别适用于推荐系统领域。HugeCTR 的设计目标包括:
- 快速:在包括 MLPerf 在内的推荐基准测试中表现出色。
- 易用:无论您是数据科学家还是机器学习从业者,我们都使其易于使用,提供丰富的文档、笔记本和示例。
- 领域特定:提供必要的功能,以便您可以高效地部署大型推荐模型。
项目快速启动
安装 HugeCTR
首先,确保您的系统满足 HugeCTR 的依赖要求,然后通过以下命令克隆项目并安装:
git clone https://github.com/NVIDIA-Merlin/HugeCTR.git
cd HugeCTR
mkdir build
cd build
cmake ..
make -j
训练模型
以下是一个简单的示例,展示如何使用 HugeCTR 训练一个模型:
import hugectr
from mpi4py import MPI
# 初始化 MPI
comm = MPI.COMM_WORLD
# 创建 HugeCTR 会话
solver = hugectr.CreateSolver(max_eval_batches = 100,
batchsize_eval = 1000,
batchsize = 1000,
vvgpu = [[0]],
use_mixed_precision = False,
i64_input_key = True,
use_algorithm_search = True,
use_cuda_graph = True,
repeat_dataset = True)
# 加载数据
reader = hugectr.DataReaderParams(data_reader_type = hugectr.DataReaderType_t.Parquet,
source = ["train.parquet"],
eval_source = "eval.parquet",
check_type = hugectr.Check_t.Non)
# 创建模型
optimizer = hugectr.CreateOptimizer(optimizer_type = hugectr.Optimizer_t.Adam,
update_type = hugectr.Update_t.Global,
beta1 = 0.9,
beta2 = 0.999,
epsilon = 0.0000001)
model = hugectr.Model(solver, reader, optimizer)
model.add(hugectr.Input(label_dim = 1, label_name = "label",
dense_dim = 13, dense_name = "dense",
data_reader_sparse_param_array =
[hugectr.DataReaderSparseParam("data1", 1, True, 26)]))
model.add(hugectr.SparseEmbedding(embedding_type = hugectr.Embedding_t.DistributedSlotSparseEmbeddingHash,
workspace_size_per_gpu_in_mb = 28,
embedding_vec_size = 16,
combiner = "sum",
sparse_embedding_name = "sparse_embedding1",
bottom_name = "data1",
optimizer = optimizer))
model.add(hugectr.DenseLayer(layer_type = hugectr.Layer_t.InnerProduct,
bottom_names = ["dense"],
top_names = ["fc1"],
num_output = 1024))
model.add(hugectr.DenseLayer(layer_type = hugectr.Layer_t.ReLU,
bottom_names = ["fc1"],
top_names = ["relu1"]))
model.add(hugectr.DenseLayer(layer_type = hugectr.Layer_t.InnerProduct,
bottom_names = ["relu1"],
top_names = ["fc2"],
num_output = 1024))
model.add(hugectr.DenseLayer(layer_type = hugectr.Layer_t.ReLU,
bottom_names = ["fc2"],
top_names = ["relu2"]))
model.add(hugectr.DenseLayer(layer_type = hugectr.Layer_t.InnerProduct,
bottom_names = ["relu2"],
top_names = ["fc3"],
num_output = 1))
model.add(hugectr.DenseLayer(layer_type = hugectr.Layer_t