【DSW Gallery】HybridBackend 极简教程: 在 GPU 上加速推荐模型训练

本文涉及的产品
模型在线服务 PAI-EAS,A10/V100等 500元 1个月
模型训练 PAI-DLC,100CU*H 3个月
交互式建模 PAI-DSW,每月250计算时 3个月
简介: 本文介绍了如何使用 HybridBackend 在 GPU 上加速一个示例推荐模型的训练。HybridBackend 是阿里巴巴提供的一个工业级稀疏模型训练框架,可以帮助用户轻松提升GPU上的稀疏模型训练的计算吞吐。

直接使用

请打开HybridBackend 极简教程: 在 GPU 上加速推荐模型训练,并点击右上角 “ 在DSW中打开” 。

image.png


HybridBackend Quickstart

In this tutorial, we use HybridBackend to speed up training of a sample ranking model based on stacked DCNv2 on Taobao ad click datasets.

Why HybridBackend

  • Training industrial recommendation models can benefit greatly from GPUs
  • Embedding layer becomes wider, consuming up to thousands of feature fields, which requires larger memory bandwidth;
  • Feature interaction layer is going deeper by leveraging multiple DNN submodules over different subsets of features, which requires higher computing capability;
  • GPUs provide much higher computing capability, larger memory bandwidth, and faster data movement;
  • Industrial recommendation models do not take full advantage of the GPU resources by canonical training frameworks
  • Industrial recommendation models contain up to a thousand of input feature fields, introducing fragmentary and memory-intensive operations;
  • The multiple constituent feature interaction submodules introduce substantial small-sized compute kernels;
  • Training framework of industrial recommendation models must be less-invasive and compatible with existing workflow
  • Training is only a part of production recommendation system, it needs great effort to modify inference pipeline;
  • AI scientists write models in a variety of ways, especially in a big team.

HybridBackend enables speeding up of training industrial recommendation models on GPUs with minimum effort. In this tutorial, you will learn how to use HybridBackend to make training of industrial recommendation models much faster.

See HybridBackend GitHub repo and the paper for more information.

Requirements

  • Hardware
  • Modern GPU and interconnect (e.g. A10 / PCIe Gen4)
  • Fast data storage (e.g. ESSD)
  • Software
  • Ubuntu 20.04 or above
  • Python 3.8 or above
  • CUDA 11.4
  • TensorFlow 1.15
  • TFRecord Format
  • Parquet Format
!pip3 install hybridbackend-tf115-cu114

Sample ranking model

In this tutorial, a sample ranking model based on stacked DCNv2 is used. You can see code in ranking for more details.

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
from tensorflow.python.util import module_wrapper as deprecation
deprecation._PER_MODULE_WARNING_LIMIT = 0
tf.get_logger().propagate = False
from ranking.data import DataSpec
from ranking.model import stacked_dcn_v2
from ranking.model import wide_and_deep_features
# Global configuration
train_max_steps = 100
train_batch_size = 16000
data_spec = DataSpec.read('ranking/taobao/data/spec.json')
def train(iterator, embedding_weight_device, dnn_device, hooks):
  batch = iterator.get_next()
  batch.pop('ts')
  labels = tf.reshape(tf.to_float(batch.pop('label')), shape=[-1, 1])
  wide_features, deep_features = wide_and_deep_features(
    batch,
    data_spec.defaults,
    data_spec.norms,
    data_spec.logs,
    data_spec.embedding_dims,
    data_spec.embedding_sizes,
    embedding_weight_device)
  with tf.device(dnn_device):
    logits = stacked_dcn_v2(
      wide_features + deep_features,
      [1024, 1024, 512, 256, 1])
    loss = tf.reduce_mean(tf.keras.losses.binary_crossentropy(labels, logits))
    step = tf.train.get_or_create_global_step()
    opt = tf.train.AdagradOptimizer(learning_rate=0.001)
    train_op = opt.minimize(loss, global_step=step)
  hooks.append(tf.train.StepCounterHook(10))
  hooks.append(tf.train.StopAtStepHook(train_max_steps))
  config = tf.ConfigProto(allow_soft_placement=True)
  config.gpu_options.allow_growth = True
  config.gpu_options.force_gpu_compatible = True
  with tf.train.MonitoredTrainingSession(
      '', hooks=hooks, config=config) as sess:
    while not sess.should_stop():
      sess.run(train_op)

Training without HybridBackend

Without HybridBackend, training the sample ranking model underutilizes GPUs.

# Download training data in TFRecord format
!wget http://easyrec.oss-cn-beijing.aliyuncs.com/data/taobao/day_0.tfrecord
with tf.Graph().as_default():
  ds = tf.data.TFRecordDataset('./day_0.tfrecord', compression_type='GZIP')
  ds = ds.batch(train_batch_size, drop_remainder=True)
  ds = ds.map(
    lambda batch: tf.io.parse_example(batch, data_spec.to_example_spec()))
  ds = ds.prefetch(2)
  iterator = tf.data.make_one_shot_iterator(ds)
  with tf.device('/gpu:0'):
    train(iterator, '/cpu:0', '/gpu:0', [])

Training with HybridBackend

By just one-line importing, HybridBackend uses packing and interleaving to speed up embedding layers dramatically and automatically.

# Note: Once HybridBackend is on, you need to restart notebook to turn it off.
import hybridbackend.tensorflow as hb
# Exact same code except HybridBackend is on.
with tf.Graph().as_default():
  ds = tf.data.TFRecordDataset('./day_0.tfrecord', compression_type='GZIP')
  ds = ds.batch(train_batch_size, drop_remainder=True)
  ds = ds.map(
    lambda batch: tf.io.parse_example(batch, data_spec.to_example_spec()))
  ds = ds.prefetch(2)
  iterator = tf.data.make_one_shot_iterator(ds)
  with tf.device('/gpu:0'):
    train(iterator, '/cpu:0', '/gpu:0', [])

Training with HybridBackend (Optimized data pipeline)

Even greater training performance gains can be archived if we use optimized data pipeline provided by HybridBackend.

# Download training data in Parquet format
!wget http://easyrec.oss-cn-beijing.aliyuncs.com/data/taobao/day_0.parquet
# Note: Once HybridBackend is on, you need to restart notebook to turn it off.
import hybridbackend.tensorflow as hb
with tf.Graph().as_default():
  ds = hb.data.ParquetDataset(
    './day_0.parquet',
    batch_size=train_batch_size,
    num_parallel_parser_calls=tf.data.experimental.AUTOTUNE,
    drop_remainder=True)
  ds = ds.apply(hb.data.to_sparse())
  ds = ds.prefetch(2)
  iterator = tf.data.make_one_shot_iterator(ds)
  with tf.device('/gpu:0'):
    iterator = hb.data.Iterator(iterator, 2)
    train(iterator, '/cpu:0', '/gpu:0', [hb.data.Iterator.Hook()])


相关实践学习
在云上部署ChatGLM2-6B大模型(GPU版)
ChatGLM2-6B是由智谱AI及清华KEG实验室于2023年6月发布的中英双语对话开源大模型。通过本实验,可以学习如何配置AIGC开发环境,如何部署ChatGLM2-6B大模型。
相关文章
|
8月前
|
人工智能 Linux iOS开发
exo:22.1K Star!一个能让任何人利用日常设备构建AI集群的强大工具,组成一个虚拟GPU在多台设备上并行运行模型
exo 是一款由 exo labs 维护的开源项目,能够让你利用家中的日常设备(如 iPhone、iPad、Android、Mac 和 Linux)构建强大的 AI 集群,支持多种大模型和分布式推理。
1761 100
|
7月前
|
存储 测试技术 对象存储
容器计算服务ACS单张GPU即可快速搭建QwQ-32B推理模型
阿里云最新发布的QwQ-32B模型拥有320亿参数,通过强化学习大幅度提升了模型推理能力,其性能与DeepSeek-R1 671B媲美,本文介绍如何使用ACS算力部署生产可用的QwQ-32B模型推理服务。
|
12月前
|
并行计算 Shell TensorFlow
Tensorflow-GPU训练MTCNN出现错误-Could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED
在使用TensorFlow-GPU训练MTCNN时,如果遇到“Could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED”错误,通常是由于TensorFlow、CUDA和cuDNN版本不兼容或显存分配问题导致的,可以通过安装匹配的版本或在代码中设置动态显存分配来解决。
202 1
Tensorflow-GPU训练MTCNN出现错误-Could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED
|
7月前
|
并行计算 PyTorch 算法框架/工具
融合AMD与NVIDIA GPU集群的MLOps:异构计算环境中的分布式训练架构实践
本文探讨了如何通过技术手段混合使用AMD与NVIDIA GPU集群以支持PyTorch分布式训练。面对CUDA与ROCm框架互操作性不足的问题,文章提出利用UCC和UCX等统一通信框架实现高效数据传输,并在异构Kubernetes集群中部署任务。通过解决轻度与强度异构环境下的挑战,如计算能力不平衡、内存容量差异及通信性能优化,文章展示了如何无需重构代码即可充分利用异构硬件资源。尽管存在RDMA验证不足、通信性能次优等局限性,但该方案为最大化GPU资源利用率、降低供应商锁定提供了可行路径。源代码已公开,供读者参考实践。
483 3
融合AMD与NVIDIA GPU集群的MLOps:异构计算环境中的分布式训练架构实践
|
7月前
|
人工智能 自然语言处理 API
Proxy Lite:仅3B参数的开源视觉模型!快速实现网页自动化,支持在消费级GPU上运行
Proxy Lite 是一款开源的轻量级视觉语言模型,支持自动化网页任务,能够像人类一样操作浏览器,完成网页交互、数据抓取、表单填写等重复性工作,显著降低自动化成本。
491 11
Proxy Lite:仅3B参数的开源视觉模型!快速实现网页自动化,支持在消费级GPU上运行
|
7月前
|
机器学习/深度学习 人工智能 物联网
MiniMind:2小时训练出你的专属AI!开源轻量级语言模型,个人GPU轻松搞定
MiniMind 是一个开源的超小型语言模型项目,帮助开发者以极低成本从零开始训练自己的语言模型,最小版本仅需25.8M参数,适合在普通个人GPU上快速训练。
1248 10
MiniMind:2小时训练出你的专属AI!开源轻量级语言模型,个人GPU轻松搞定
|
7月前
|
存储 人工智能 固态存储
轻量级AI革命:无需GPU就能运算的DeepSeek-R1-1.5B模型及其低配部署指南
随着AI技术发展,大语言模型成为产业智能化的关键工具。DeepSeek系列模型以其创新架构和高效性能备受关注,其中R1-1.5B作为参数量最小的版本,适合资源受限场景。其部署仅需4核CPU、8GB RAM及15GB SSD,适用于移动对话、智能助手等任务。相比参数更大的R1-35B与R1-67B+,R1-1.5B成本低、效率高,支持数学计算、代码生成等多领域应用,是个人开发者和初创企业的理想选择。未来,DeepSeek有望推出更多小型化模型,拓展低资源设备的AI生态。
1245 8
|
8月前
|
机器学习/深度学习 人工智能 并行计算
Unsloth:学生党福音!开源神器让大模型训练提速10倍:单GPU跑Llama3,5小时变30分钟
Unsloth 是一款开源的大语言模型微调工具,支持 Llama-3、Mistral、Phi-4 等主流 LLM,通过优化计算步骤和手写 GPU 内核,显著提升训练速度并减少内存使用。
1028 3
Unsloth:学生党福音!开源神器让大模型训练提速10倍:单GPU跑Llama3,5小时变30分钟
|
7月前
|
人工智能 负载均衡 调度
COMET:字节跳动开源MoE训练加速神器,单层1.96倍性能提升,节省百万GPU小时
COMET是字节跳动推出的针对Mixture-of-Experts(MoE)模型的优化系统,通过细粒度的计算-通信重叠技术,显著提升分布式训练效率,支持多种并行策略和大规模集群部署。
309 9
|
8月前
|
存储 人工智能 算法
Magic 1-For-1:北大联合英伟达推出的高质量视频生成量化模型,支持在消费级GPU上快速生成
北京大学、Hedra Inc. 和 Nvidia 联合推出的 Magic 1-For-1 模型,优化内存消耗和推理延迟,快速生成高质量视频片段。
380 3
Magic 1-For-1:北大联合英伟达推出的高质量视频生成量化模型,支持在消费级GPU上快速生成

热门文章

最新文章

相关产品

  • 人工智能平台 PAI