网站链接dw怎么做高端网站开发 金蝶
2026/2/25 6:18:39 网站建设 项目流程
网站链接dw怎么做,高端网站开发 金蝶,liferay做网站好吗,西安做网站电话vLLM 是一款专为大语言模型推理加速而设计的框架#xff0c;实现了 KV 缓存内存几乎零浪费#xff0c;解决了内存管理瓶颈问题。 更多 vLLM 中文文档及教程可访问 →vllm.hyper.ai/ *在线运行 vLLM 入门教程#xff1a;零基础分步指南 源码examples/offline_inference/rl…vLLM 是一款专为大语言模型推理加速而设计的框架实现了 KV 缓存内存几乎零浪费解决了内存管理瓶颈问题。更多 vLLM 中文文档及教程可访问 →vllm.hyper.ai/*在线运行 vLLM 入门教程零基础分步指南源码examples/offline_inference/rlhf_colocate.py# SPDX-License-Identifier: Apache-2.0 一个简单的演示展示如何将 vLLM 工作进程与训练执行器training actors 协同部署在同一 GPU上适用于类 RLHF 应用。 关键要点 - 通过正确设置 VLLM_RAY_PER_WORKER_GPUS 和 VLLM_RAY_BUNDLE_INDICES 使用 Ray 控制 vLLM 工作进程的部署位置 - 使用 CUDA-IPC 传递张量因为在同一 GPU 上存在多个进程时 NCCL 无法正常工作 import os import ray import torch from ray.util.placement_group import placement_group from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy from vllm import LLM class MyLLM(LLM): def __init__(self, *args, bundle_indices: list, **kwargs): # 临时方案使脚本能运行 # 阻止Ray在顶层操作CUDA_VISIBLE_DEVICES os.environ.pop(CUDA_VISIBLE_DEVICES, None) # 每个工作进程将使用 0.4 个 GPU这样我们可以在同一 GPU 上调度 2 个实例 os.environ[VLLM_RAY_PER_WORKER_GPUS] 0.4 os.environ[VLLM_RAY_BUNDLE_INDICES] ,.join( map(str, bundle_indices)) print(fcreating LLM with bundle_indices{bundle_indices}) super().__init__(*args, **kwargs) class RayTrainingActor: def __init__(self): # ray 将 CUDA_VISIBLE_DEVICES 设置为分配的 GPU from transformers import AutoModelForCausalLM self.model AutoModelForCausalLM.from_pretrained(facebook/opt-125m) self.model.to(cuda:0) for name, p in self.model.named_parameters(): p.data.zero_() torch.cuda.synchronize() # get_device_uuid 的参数是 # 可见设备中 GPU 的索引 from vllm.platforms import current_platform self.device_uuid current_platform.get_device_uuid(0) def report_device_id(self) - str: return self.device_uuid def get_weight_ipc_handles(self): from torch.multiprocessing.reductions import reduce_tensor data {} for name, p in self.model.named_parameters(): # 训练执行器training actor可能只拥有部分权重 # 需要从所有执行器进行 all-gather 操作获取完整权重。 # 出于演示目的此处我们假设所有训练执行器都拥有完整权重。 data[name] reduce_tensor(p.detach()) return {self.device_uuid: data} # ray 管理4 GPU os.environ[CUDA_VISIBLE_DEVICES] 0,1,2,3 ray.init() # 我们需要将 vLLM 实例和训练执行器training actor协同部署在同一组 GPU 上 # 具体部署方案如下 # GPU 0 和 1训练执行器 0、1 和 vLLM 实例 0TP2 # GPU 2 和 3训练执行器 2、3 和 vLLM 实例 1TP2 pg placement_group([{GPU: 1, CPU: 0}] * 4) ray.get(pg.ready()) print(fplacement group has bundles {pg.bundle_specs}) training_actors [] training_actor_device_ids [] inference_engines [] inference_engine_device_ids [] for bundle_index in [0, 1, 2, 3]: training_actor ray.remote( num_cpus0, num_gpus0.4, scheduling_strategyPlacementGroupSchedulingStrategy( placement_grouppg, placement_group_capture_child_tasksTrue, placement_group_bundle_indexbundle_index, ), )(RayTrainingActor).remote() training_actors.append(training_actor) for bundle_index, training_actor in enumerate(training_actors): device_id ray.get(training_actor.report_device_id.remote()) print(ftraining actor {bundle_index} is on {device_id}) training_actor_device_ids.append(device_id) for (i, bundle_indices) in enumerate([[0, 1], [2, 3]]): # and cause unexpected behaviors. # 重要:创建 vLLM 实例时我们需要 # 确保目标 GPU 上没有 GPU 活动 # 否则它们将干扰 vLLM 内存分析 # 并引起意外的行为。 llm ray.remote( num_cpus0, num_gpus0, scheduling_strategyPlacementGroupSchedulingStrategy( placement_grouppg, placement_group_capture_child_tasksTrue, ), )(MyLLM).remote( modelfacebook/opt-125m, enforce_eagerTrue, worker_extension_clsrlhf_utils.ColocateWorkerExtension, tensor_parallel_size2, distributed_executor_backendray, gpu_memory_utilization0.4, bundle_indicesbundle_indices, ) inference_engines.append(llm) # dont call any method on the inference engine here, # otherwise it will block until the vLLM instance is created. # 在此处的推理引擎上不要调用任何方法 # 否则它将锁定直到创建 vLLM 实例。 for i, llm in enumerate(inference_engines): inference_engine_device_ids.append( ray.get(llm.collective_rpc.remote(report_device_id, argstuple()))) print(finference engine {i} is on {inference_engine_device_ids[-1]}) # 检查部署情况 # 前两个训练执行器(training actors)应当 # 与第一个推理引擎(inference engine)部署在同一GPU上 assert training_actor_device_ids[:2] inference_engine_device_ids[0] # 最后两个训练执行器(training actors)应当 # 与第二个推理引擎(inference engine)部署在同一GPU上 assert training_actor_device_ids[2:] inference_engine_device_ids[1] print(gather all the IPC handles from the training actors) ipc_handles {} for actor in training_actors: ipc_handles.update(ray.get(actor.get_weight_ipc_handles.remote())) print(update the weights of the inference engines) for llm in inference_engines: ray.get( llm.collective_rpc.remote(update_weights_from_ipc_handles, args(ipc_handles, ))) print(check if the weights are updated) for llm in inference_engines: assert ray.get( llm.collective_rpc.remote(check_weights_changed, argstuple()))

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询