Torch-RecHub Documentation

repository·main·Indexed 22 days ago

https://github.com/datawhalechina/torch-rechub

A lightweight PyTorch-based framework for building production-grade recommender systems. It features over 30 pre-built models for matching, ranking, and multi-task learning, with built-in support for ONNX deployment and hardware accelerators. The framework includes a comprehensive benchmarking suite for retrieval (e.g., DSSM, YoutubeDNN), CTR prediction (e.g., WideDeep, DeepFM, DCN), and multi-task learning (e.g., ESMM, MMOE, PLE), along with data preprocessing tools for datasets like Amazon Books, Movielens, and YiDian-News.

Tokens
131.6K
Snippets
307
Records
445
Agent score
78%

What's inside Torch-RecHub

  1. Overview of the Torch-RecHub model library

    main

    Torch-RecHub provides a collection of PyTorch-based recommendation models organized by their role in the recommendation pipeline. The library covers four primary stages:

    1. Ranking Models: Predict click-through rates (CTR) or user preference scores during fine ranking.
    2. Matching Models: Retrieve candidates from large item collections during the candidate generation stage.
    3. Multi-Task Models: Jointly optimize multiple related tasks to improve model generalization.
    4. Generative Recommendation Models: Use generative architectures to produce personalized recommendations.
  2. Overview of Torch-RecHub features

    main

    Torch-RecHub is a lightweight, extensible, and high-performance PyTorch framework designed for recommendation systems. It provides unified workflows across several key recommendation stages and capabilities:

    • Ranking Workflows: Support for production-ready models like WideDeep, DeepFM, DIN, BST, DIEN, and DCN.
    • Matching and Retrieval: Support for two-tower retrieval, sequential recall, multi-interest modeling, and recall evaluation.
    • Multi-Task Learning (MTL): Unified training for architectures such as ESMM, MMOE, PLE, and AITM.
    • Generative Extensions: Support for sequence modeling, semantic ID quantization, and generative recommendation workflows.
    • Deployment & Serving: Built-in support for ONNX export and validation, and integration with vector indexing tools like Annoy, Faiss, or Milvus.
    • Experiment Management: Tools for experiment visibility, including callbacks, tracking, and visualization.
    • Unified Data Pipeline: A consistent feature schema and data pipeline that can be reused across ranking, matching, and tutorials.
  3. Overview of Torch-RecHub

    main

    Torch-RecHub is a lightweight, efficient, and easy-to-use PyTorch-based framework for building industrial-grade recommendation systems. It allows users to implement complex recommendation tasks with minimal code (as little as 10 lines) and provides over 30 out-of-the-box models covering retrieval (matching), ranking, multi-task learning, and generative recommendation.

    Key capabilities include:

    • Hardware Support: CPU, NVIDIA CUDA, AMD ROCm, and Huawei Ascend NPU.
    • Model Library: 30+ algorithms including DSSM, WideDeep, DeepFM, MMoE, etc.
    • Deployment: One-click ONNX export for production environments.
    • Data Processing: Support for PySpark-based processing and Parquet via PyArrow.
    • Experiment Tracking: Integrated support for WandB, SwanLab, and TensorBoardX.
    • Modular Design: Easy to extend with new models, datasets, and metrics.
  4. Overview of Torch-RecHub Model Families

    main

    Torch-RecHub provides specialized models categorized by recommendation stage:

    Ranking Models (CTR Prediction)

    Used for fine-grained scoring of candidates.

    • DeepFM: Combines FM and deep networks.
    • Wide&Deep: Combines memorization and generalization.
    • DCN / DCNv2: Uses explicit feature crossing.
    • DIN: Target-aware attention over user history.
    • DIEN: Models interest evolution.
    • BST: Transformer-based sequence ranking.

    Retrieval Models (Matching)

    Used for candidate generation/two-tower architectures.

    • DSSM: Classic two-tower semantic matching.
    • YoutubeDNN: YouTube-style deep retrieval.
    • MIND: Multi-interest retrieval using capsules.

    Multi-Task Models

    Used for joint optimization of multiple objectives.

    • MMOE: Multi-gate mixture-of-experts.
    • PLE: Progressive layered extraction.
  5. Supported Recommendation Models

    main

    Torch-RecHub supports over 30 mainstream recommendation models categorized into four main types:

    1. Ranking Models: Focused on CTR prediction (e.g., DeepFM, Wide&Deep, DCN, DCN-v2, DIN, DIEN, BST, AFM, AutoInt, FiBiNET, DeepFFM, EDCN).
    2. Matching Models: Two-tower or retrieval models (e.g., DSSM, YoutubeDNN, YoutubeSBC, MIND, SINE, GRU4Rec, SASRec, NARM, STAMP, ComiRec).
    3. Multi-Task Models: Models designed for multiple objectives (e.g., ESMM, MMoE, PLE, AITM, SharedBottom).
    4. Generative Recommendation: Cutting-edge generative approaches (e.g., HSTU, HLLM, TIGER).
  6. Understand the Torch-RecHub project structure

    main

    The repository is organized into core library components, example scripts, and configuration files:

    • torch_rechub/: The core library.
      • basic/: Fundamental building blocks like activation.py, features.py, layers.py, loss_func.py, and metric.py.
      • models/: Implementation of recommendation algorithms categorized by task: matching/ (e.g., DSSM, MIND), ranking/ (e.g., WideDeep, DeepFM), and multi_task/ (e.g., MMoE, ESMM).
      • trainers/: Specialized training frameworks for different tasks: ctr_trainer.py, match_trainer.py, and mtl_trainer.py.
      • utils/: Utilities for data.py, match.py, mtl.py, and onnx_export.py.
    • examples/: Task-specific scripts for matching/, ranking/, and generative/ (e.g., HSTU, HLLM).
    • config/: Configuration files for experiments.
    • tutorials/: Jupyter notebooks for guided learning.
  7. Overview of Torch-RecHub architecture and components

    main

    Torch-RecHub is a modular recommendation system framework built on PyTorch designed for research and application. It decouples model definition from training and uses native PyTorch functions to ensure hardware acceleration (CPU, NVIDIA CUDA, AMD ROCm, Huawei Ascend NPU) and ease of extension.

    The framework is organized into five core functional components:

    1. Feature Processing: Manages dense, sparse, and sequence features.
    2. Data Pipeline: Handles data loading, preprocessing, and dataloader generation for both ranking and matching models.
    3. Model Library: Contains implementations for various recommendation paradigms (Ranking, Matching, Multi-Task, and Generative).
    4. Training & Evaluation: Provides a unified interface for training, evaluation, prediction, and ONNX export.
    5. Development Tools: Includes utilities for ONNX export, model visualization, callbacks, and loss functions.
  8. What is PLE (Progressive Layered Extraction)?

    main

    PLE is a multi-task learning (MTL) model designed to solve the seesaw phenomenon, where optimizing one task negatively impacts another. Unlike MMOE, which uses only shared experts, PLE utilizes Customized Gate Control (CGC) to assign both task-specific experts and shared experts. This allows for better task separation and adaptive combination of features through gate networks.

    Key Components:

    • Task-Specific Experts: Dedicated networks for each individual task.
    • Shared Experts: Networks shared across all tasks.
    • Customized Gate (CGC): Combines task-specific and shared experts for each task.
    • Multi-Level Support: Allows stacking multiple CGC levels for progressive feature extraction.
    • Task Towers: Independent prediction towers for each task.
  9. What is DeepFM and when to use it

    main

    DeepFM (Deep Factorization Machine) is a ranking model that combines Factorization Machines (FM) with Deep Neural Networks (DNN). It is designed to capture both low-order (pairwise) and high-order (nonlinear) feature interactions simultaneously without manual feature engineering.

    Key Architecture Components:

    • FM part: Captures pairwise feature interaction patterns.
    • Deep part: Captures higher-order nonlinear interactions via multi-layer fully connected networks.
    • Shared embeddings: Both branches share the same bottom embedding layer to reduce parameter count.

    Best Use Cases:

    • Click-through rate (CTR) prediction.
    • Ad recommendation ranking.
    • Scenarios requiring both low-order and high-order feature interactions.
  10. What is DSSM and when to use it

    main

    DSSM (Deep Structured Semantic Model) is a two-tower architecture used primarily in the retrieval stage of recommendation systems. It consists of a User Tower and an Item Tower that map features into a shared vector space. Matching scores are computed using cosine similarity or dot products.

    Key Use Cases:

    • Fast filtering of large candidate sets via vector search.
    • Search relevance matching.
    • Online real-time services (supports offline precomputation of user/item vectors).
  11. What is Behavior Sequence Transformer (BST)?

    main

    BST (Behavior Sequence Transformer) is a ranking model that incorporates the Transformer self-attention mechanism into recommendation systems. Unlike DIN (Deep Interest Network), which focuses on the relationship between a target item and historical items, BST uses multi-head self-attention to capture dependencies between any two items within a user's behavior sequence.

    Architecture Components:

    • Embedding Layer: Encodes user, item, and behavior sequence features.
    • Transformer Encoder: Applies self-attention after concatenating the behavior sequence and the target item.
    • MLP Layer: Concatenates Transformer output with other features to produce a prediction score.

    Best Use Cases:

    • CTR (Click-Through Rate) prediction.
    • Scenarios with long behavior sequences and complex item dependencies.
    • When stronger sequence modeling is required compared to RNN-based methods like DIN or DIEN.
  12. Overview of the MIND model

    main

    MIND (Multi-Interest Network with Dynamic Routing) is a multi-interest retrieval model designed for the retrieval stage of recommendation systems, particularly where users have diverse interests (e.g., e-commerce).

    Unlike single-vector models like DSSM, MIND uses a Capsule Network with dynamic routing to extract multiple interest vectors from a user's behavior sequence. This results in a user representation with shape [batch_size, interest_num, embed_dim].

    Key Architecture Components:

    • Embedding Layer: Encodes user attributes and historical behavior.
    • Capsule Network: Extracts multiple interest vectors via dynamic routing.
    • Training: Uses list-wise training (Softmax) via mode=2 in MatchTrainer.