跳转到主要内容

未提供项目描述

项目描述

Merlin Systems

PyPI - Python Version PyPI version shields.io GitHub License Documentation

Merlin Systems提供工具,用于将推荐模型与其他生产推荐系统元素(如特征存储、最近邻搜索和探索策略)结合起来,形成端到端推荐管道,这些管道可以使用Triton Inference Server提供。

快速入门

Merlin Systems使用Merlin Operator DAG API,与NVTabular中用于特征工程相同的API,来创建服务集合。要将特征工程工作流程和Tensorflow模型组合到推理管道中

import tensorflow as tf

from merlin.systems.dag import Ensemble
from merlin.systems.dag.ops import PredictTensorflow, TransformWorkflow
from nvtabular.workflow import Workflow

# Load saved NVTabular workflow and TensorFlow model
workflow = Workflow.load(nvtabular_workflow_path)
model = tf.keras.models.load_model(tf_model_path)

# Remove target/label columns from feature processing workflowk
workflow = workflow.remove_inputs([<target_columns>])

# Define ensemble pipeline
pipeline = (
	workflow.input_schema.column_names >>
	TransformWorkflow(workflow) >>
	PredictTensorflow(model)
)

# Export artifacts to disk
ensemble = Ensemble(pipeline, workflow.input_schema)
ensemble.export(export_path)

导出您的集合后,您可以引用目录以运行Triton Inference Server的一个实例来托管您的集合。

tritonserver --model-repository=/export_path/

请参阅Merlin示例笔记本,了解如何使用Merlin模型训练和评估排名模型,然后如何在Triton Inference Server上以集合形式提供服务。

对于使用XGBoost和隐式进行模型训练,并使用系统进行服务的场景,您可以访问以下示例

构建四阶段推荐流程

Merlin系统还可以构建更复杂的托管流程,这些流程集成多个模型和外部工具(如特征存储和最近邻搜索)。

# Load artifacts for the pipeline
retrieval_model = tf.keras.models.load_model(retrieval_model_path)
ranking_model = tf.keras.models.load_model(ranking_model_path)
feature_store = feast.FeatureStore(feast_repo_path)

# Define the fields expected in requests
request_schema = Schema([
    ColumnSchema("user_id", dtype=np.int32),
])

# Fetch user features, use them to a compute user vector with retrieval model,
# and find candidate items closest to the user vector with nearest neighbor search
user_features = request_schema.column_names >> QueryFeast.from_feature_view(
    store=feature_store, view="user_features", column="user_id"
)

retrieval = (
    user_features
    >> PredictTensorflow(retrieval_model_path)
    >> QueryFaiss(faiss_index_path, topk=100)
)

# Filter out candidate items that have already interacted with
# in the current session and fetch item features for the rest
filtering = retrieval["candidate_ids"] >> FilterCandidates(
    filter_out=user_features["movie_ids"]
)

item_features = filtering >> QueryFeast.from_feature_view(
    store=feature_store, view="movie_features", column="filtered_ids",
)

# Join user and item features for the candidates and use them to predict relevance scores
combined_features = item_features >> UnrollFeatures(
    "movie_id", user_features, unrolled_prefix="user"
)

ranking = combined_features >> PredictTensorflow(ranking_model_path)

# Sort candidate items by relevance score with some randomized exploration
ordering = combined_features["movie_id"] >> SoftmaxSampling(
    relevance_col=ranking["output"], topk=10, temperature=20.0
)

# Create and export the ensemble
ensemble = Ensemble(ordering, request_schema)
ensemble.export("./ensemble")

有关使用Merlin模型和系统探索building-and-deploying-multi-stage-RecSys笔记本的示例,请参阅示例笔记本

安装

Merlin系统需要Triton推理服务器和Tensorflow。最简单的设置是使用Merlin Tensorflow推理Docker容器,其中已预先安装。

使用Pip安装Merlin系统

您可以使用pip安装Merlin系统。

pip install merlin-systems

从源代码安装Merlin系统

可以通过克隆GitHub存储库并运行setup.py从源代码安装Merlin系统。

git clone https://github.com/NVIDIA-Merlin/systems.git
cd systems && python setup.py develop

从Docker运行Merlin系统

Merlin系统安装在多个Docker容器中,这些容器可通过NVIDIA GPU Cloud (NGC)目录获取。以下表格列出了包含用于Merlin的Triton推理服务器的容器。

容器名称 容器位置 功能
merlin-hugectr https://catalog.ngc.nvidia.com/orgs/nvidia/teams/merlin/containers/merlin-hugectr Merlin框架、HugeCTR和Triton推理服务器
merlin-tensorflow https://catalog.ngc.nvidia.com/orgs/nvidia/teams/merlin/containers/merlin-tensorflow 仅支持Tensorflow的Merlin框架和Triton推理服务器

如果您想添加对GPU加速工作流的支持,您首先需要安装NVIDIA容器工具包,以提供Docker的GPU支持。您可以使用上表中引用的NGC链接获取有关如何启动和运行这些容器的更多信息。

反馈和支持

要报告错误或获取帮助,请打开问题

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码发行版

merlin-systems-23.8.0.tar.gz (72.1 kB 查看哈希值)

上传时间 源代码

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面