rlinf 0.2.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rlinf/__init__.py +17 -0
- rlinf/agents/__init__.py +13 -0
- rlinf/agents/multiturn_demo/__init__.py +13 -0
- rlinf/agents/multiturn_demo/fake_tool_worker.py +64 -0
- rlinf/agents/multiturn_demo/mcp_agent_loop.py +221 -0
- rlinf/agents/multiturn_demo/mcp_filesystem_worker.py +577 -0
- rlinf/agents/multiturn_demo/tool_agent_loop.py +163 -0
- rlinf/agents/searchr1/__init__.py +13 -0
- rlinf/agents/searchr1/search_tool_worker.py +152 -0
- rlinf/agents/searchr1/searchr1_agent_loop.py +193 -0
- rlinf/algorithms/__init__.py +14 -0
- rlinf/algorithms/advantages.py +186 -0
- rlinf/algorithms/losses.py +277 -0
- rlinf/algorithms/registry.py +118 -0
- rlinf/algorithms/rewards/__init__.py +36 -0
- rlinf/algorithms/rewards/code/__init__.py +33 -0
- rlinf/algorithms/rewards/code/code_verifier/__init__.py +13 -0
- rlinf/algorithms/rewards/code/code_verifier/verify.py +230 -0
- rlinf/algorithms/rewards/math/__init__.py +42 -0
- rlinf/algorithms/rewards/math/math_verifier/__init__.py +13 -0
- rlinf/algorithms/rewards/math/math_verifier/parser.py +441 -0
- rlinf/algorithms/rewards/math/math_verifier/verify.py +441 -0
- rlinf/algorithms/rewards/searchr1/__init__.py +161 -0
- rlinf/algorithms/rewards/vqa/__init__.py +60 -0
- rlinf/algorithms/rewards/vqa/format_rewards.py +66 -0
- rlinf/algorithms/rewards/vqa/qa_rewards.py +109 -0
- rlinf/algorithms/utils.py +359 -0
- rlinf/config.py +1255 -0
- rlinf/data/__init__.py +13 -0
- rlinf/data/datasets/__init__.py +135 -0
- rlinf/data/datasets/item.py +45 -0
- rlinf/data/datasets/math.py +228 -0
- rlinf/data/datasets/vlm.py +468 -0
- rlinf/data/datasets/world_model.py +365 -0
- rlinf/data/embodied_io_struct.py +521 -0
- rlinf/data/io_struct.py +1139 -0
- rlinf/data/replay_buffer.py +1169 -0
- rlinf/data/tokenizers.py +71 -0
- rlinf/data/tool_call/__init__.py +13 -0
- rlinf/data/tool_call/tool_io_struct.py +122 -0
- rlinf/data/utils.py +53 -0
- rlinf/envs/__init__.py +107 -0
- rlinf/envs/action_utils.py +220 -0
- rlinf/envs/behavior/__init__.py +13 -0
- rlinf/envs/behavior/behavior_env.py +312 -0
- rlinf/envs/calvin/__init__.py +129 -0
- rlinf/envs/calvin/calvin_gym_env.py +486 -0
- rlinf/envs/calvin/utils.py +75 -0
- rlinf/envs/calvin/venv.py +264 -0
- rlinf/envs/frankasim/__init__.py +19 -0
- rlinf/envs/frankasim/frankasim_env.py +722 -0
- rlinf/envs/habitat/__init__.py +17 -0
- rlinf/envs/habitat/extensions/__init__.py +13 -0
- rlinf/envs/habitat/extensions/config/vlnce_r2r.yaml +68 -0
- rlinf/envs/habitat/extensions/maps.py +357 -0
- rlinf/envs/habitat/extensions/utils.py +711 -0
- rlinf/envs/habitat/habitat_env.py +348 -0
- rlinf/envs/habitat/venv.py +246 -0
- rlinf/envs/isaaclab/__init__.py +21 -0
- rlinf/envs/isaaclab/isaaclab_env.py +264 -0
- rlinf/envs/isaaclab/tasks/__init__.py +13 -0
- rlinf/envs/isaaclab/tasks/stack_cube.py +97 -0
- rlinf/envs/isaaclab/utils.py +62 -0
- rlinf/envs/isaaclab/venv.py +118 -0
- rlinf/envs/libero/__init__.py +13 -0
- rlinf/envs/libero/libero_env.py +459 -0
- rlinf/envs/libero/utils.py +125 -0
- rlinf/envs/libero/venv.py +173 -0
- rlinf/envs/maniskill/__init__.py +33 -0
- rlinf/envs/maniskill/maniskill_env.py +406 -0
- rlinf/envs/maniskill/tasks/__init__.py +13 -0
- rlinf/envs/maniskill/tasks/put_carrot_on_plate.py +151 -0
- rlinf/envs/maniskill/tasks/put_on_in_scene_multi.py +963 -0
- rlinf/envs/maniskill/tasks/variants/__init__.py +51 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_carrot.py +77 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_ee_pose.py +289 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_image.py +105 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_instruct.py +123 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_multi_carrot.py +352 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_multi_plate.py +399 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_plate.py +97 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_position.py +231 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_position_change.py +179 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_single.py +110 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_vision_image.py +49 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_vision_texture.py +325 -0
- rlinf/envs/maniskill/tasks/variants/put_on_plate_25_vision_whole.py +364 -0
- rlinf/envs/maniskill/tasks/variants/utils.py +31 -0
- rlinf/envs/maniskill/utils.py +41 -0
- rlinf/envs/metaworld/__init__.py +61 -0
- rlinf/envs/metaworld/metaworld_env.py +442 -0
- rlinf/envs/metaworld/utils.py +21 -0
- rlinf/envs/metaworld/venv.py +170 -0
- rlinf/envs/realworld/__init__.py +26 -0
- rlinf/envs/realworld/common/camera/__init__.py +17 -0
- rlinf/envs/realworld/common/camera/camera.py +143 -0
- rlinf/envs/realworld/common/keyboard/__init__.py +13 -0
- rlinf/envs/realworld/common/keyboard/keyboard_listener.py +42 -0
- rlinf/envs/realworld/common/ros/__init__.py +17 -0
- rlinf/envs/realworld/common/ros/ros_controller.py +129 -0
- rlinf/envs/realworld/common/spacemouse/__init__.py +13 -0
- rlinf/envs/realworld/common/spacemouse/spacemouse_expert.py +74 -0
- rlinf/envs/realworld/common/video_player/__init__.py +17 -0
- rlinf/envs/realworld/common/video_player/video_player.py +55 -0
- rlinf/envs/realworld/common/wrappers/__init__.py +31 -0
- rlinf/envs/realworld/common/wrappers/euler_obs.py +39 -0
- rlinf/envs/realworld/common/wrappers/gripper_close.py +41 -0
- rlinf/envs/realworld/common/wrappers/relative_frame.py +140 -0
- rlinf/envs/realworld/common/wrappers/reward_done_wrapper.py +105 -0
- rlinf/envs/realworld/common/wrappers/spacemouse_intervention.py +72 -0
- rlinf/envs/realworld/franka/__init__.py +18 -0
- rlinf/envs/realworld/franka/franka_controller.py +375 -0
- rlinf/envs/realworld/franka/franka_env.py +544 -0
- rlinf/envs/realworld/franka/franka_robot_state.py +48 -0
- rlinf/envs/realworld/franka/tasks/__init__.py +35 -0
- rlinf/envs/realworld/franka/tasks/bottle.py +136 -0
- rlinf/envs/realworld/franka/tasks/franka_bin_relocation.py +240 -0
- rlinf/envs/realworld/franka/tasks/peg_insertion_env.py +129 -0
- rlinf/envs/realworld/franka/utils.py +105 -0
- rlinf/envs/realworld/realworld_env.py +395 -0
- rlinf/envs/realworld/venv.py +319 -0
- rlinf/envs/robocasa/__init__.py +17 -0
- rlinf/envs/robocasa/robocasa_env.py +509 -0
- rlinf/envs/robocasa/utils.py +178 -0
- rlinf/envs/robocasa/venv.py +163 -0
- rlinf/envs/robotwin/__init__.py +13 -0
- rlinf/envs/robotwin/robotwin_env.py +493 -0
- rlinf/envs/utils.py +294 -0
- rlinf/envs/venv/__init__.py +33 -0
- rlinf/envs/venv/venv.py +985 -0
- rlinf/envs/world_model/__init__.py +13 -0
- rlinf/envs/world_model/base_world_env.py +155 -0
- rlinf/envs/world_model/world_model_opensora_env.py +801 -0
- rlinf/envs/wrappers/__init__.py +17 -0
- rlinf/envs/wrappers/record_video.py +377 -0
- rlinf/hybrid_engines/__init__.py +13 -0
- rlinf/hybrid_engines/fsdp/__init__.py +49 -0
- rlinf/hybrid_engines/fsdp/fsdp_model_manager.py +605 -0
- rlinf/hybrid_engines/fsdp/strategy/__init__.py +13 -0
- rlinf/hybrid_engines/fsdp/strategy/base.py +515 -0
- rlinf/hybrid_engines/fsdp/strategy/checkpoint.py +132 -0
- rlinf/hybrid_engines/fsdp/strategy/fsdp.py +350 -0
- rlinf/hybrid_engines/fsdp/strategy/fsdp2.py +203 -0
- rlinf/hybrid_engines/fsdp/utils.py +829 -0
- rlinf/hybrid_engines/megatron/__init__.py +13 -0
- rlinf/hybrid_engines/megatron/megatron_model_manager.py +667 -0
- rlinf/hybrid_engines/megatron/utils.py +232 -0
- rlinf/hybrid_engines/sglang/common/__init__.py +13 -0
- rlinf/hybrid_engines/sglang/common/detokenizer_manager.py +57 -0
- rlinf/hybrid_engines/sglang/common/io_struct.py +52 -0
- rlinf/hybrid_engines/sglang/common/sgl_engine.py +138 -0
- rlinf/hybrid_engines/sglang/common/sgl_scheduler.py +585 -0
- rlinf/hybrid_engines/sglang/common/tokenizer_manager.py +236 -0
- rlinf/hybrid_engines/vllm/vllm_0_8_5/__init__.py +13 -0
- rlinf/hybrid_engines/vllm/vllm_0_8_5/executor.py +313 -0
- rlinf/hybrid_engines/vllm/vllm_0_8_5/weight_loader.py +43 -0
- rlinf/hybrid_engines/vllm/vllm_0_8_5/worker.py +161 -0
- rlinf/models/__init__.py +96 -0
- rlinf/models/embodiment/__init__.py +13 -0
- rlinf/models/embodiment/base_policy.py +70 -0
- rlinf/models/embodiment/cnn_policy/__init__.py +26 -0
- rlinf/models/embodiment/cnn_policy/cnn_policy.py +458 -0
- rlinf/models/embodiment/dexbotic_pi/__init__.py +120 -0
- rlinf/models/embodiment/dexbotic_pi/dexbotic_pi_policy.py +772 -0
- rlinf/models/embodiment/flow_policy/__init__.py +51 -0
- rlinf/models/embodiment/flow_policy/flow_policy.py +635 -0
- rlinf/models/embodiment/gr00t/__init__.py +82 -0
- rlinf/models/embodiment/gr00t/embodiment_tags.py +59 -0
- rlinf/models/embodiment/gr00t/gr00t_action_model.py +732 -0
- rlinf/models/embodiment/gr00t/modality_config.py +177 -0
- rlinf/models/embodiment/gr00t/simulation_io.py +198 -0
- rlinf/models/embodiment/gr00t/utils.py +127 -0
- rlinf/models/embodiment/mlp_policy/__init__.py +31 -0
- rlinf/models/embodiment/mlp_policy/mlp_policy.py +288 -0
- rlinf/models/embodiment/modules/__init__.py +13 -0
- rlinf/models/embodiment/modules/batch_renorm.py +132 -0
- rlinf/models/embodiment/modules/entropy_tunning.py +69 -0
- rlinf/models/embodiment/modules/explore_noise_net.py +168 -0
- rlinf/models/embodiment/modules/flow_actor.py +469 -0
- rlinf/models/embodiment/modules/mlp.py +95 -0
- rlinf/models/embodiment/modules/q_head.py +328 -0
- rlinf/models/embodiment/modules/resnet_utils.py +158 -0
- rlinf/models/embodiment/modules/utils.py +65 -0
- rlinf/models/embodiment/modules/value_head.py +67 -0
- rlinf/models/embodiment/openpi/__init__.py +96 -0
- rlinf/models/embodiment/openpi/dataconfig/__init__.py +327 -0
- rlinf/models/embodiment/openpi/dataconfig/behavior_dataconfig.py +102 -0
- rlinf/models/embodiment/openpi/dataconfig/calvin_dataconfig.py +71 -0
- rlinf/models/embodiment/openpi/dataconfig/franka_dataconfig.py +101 -0
- rlinf/models/embodiment/openpi/dataconfig/gsenv_dataconfig.py +58 -0
- rlinf/models/embodiment/openpi/dataconfig/libero_dataconfig.py +102 -0
- rlinf/models/embodiment/openpi/dataconfig/maniskill_dataconfig.py +103 -0
- rlinf/models/embodiment/openpi/dataconfig/metaworld_dataconfig.py +68 -0
- rlinf/models/embodiment/openpi/dataconfig/robocasa_dataconfig.py +75 -0
- rlinf/models/embodiment/openpi/dataconfig/robotwin_aloha_dataconfig.py +106 -0
- rlinf/models/embodiment/openpi/openpi_action_model.py +789 -0
- rlinf/models/embodiment/openpi/policies/__init__.py +13 -0
- rlinf/models/embodiment/openpi/policies/aloha_policy.py +227 -0
- rlinf/models/embodiment/openpi/policies/behavior_policy.py +119 -0
- rlinf/models/embodiment/openpi/policies/calvin_policy.py +87 -0
- rlinf/models/embodiment/openpi/policies/franka_policy.py +137 -0
- rlinf/models/embodiment/openpi/policies/gsenv_policy.py +74 -0
- rlinf/models/embodiment/openpi/policies/libero_policy.py +118 -0
- rlinf/models/embodiment/openpi/policies/maniskill_policy.py +114 -0
- rlinf/models/embodiment/openpi/policies/metaworld_policy.py +75 -0
- rlinf/models/embodiment/openpi/policies/robocasa_policy.py +126 -0
- rlinf/models/embodiment/openvla/__init__.py +104 -0
- rlinf/models/embodiment/openvla/openvla_action_model.py +808 -0
- rlinf/models/embodiment/openvla_oft/__init__.py +32 -0
- rlinf/models/embodiment/openvla_oft/official/__init__.py +118 -0
- rlinf/models/embodiment/openvla_oft/official/openvla_oft_action_model.py +703 -0
- rlinf/models/embodiment/openvla_oft/openvla_utils.py +193 -0
- rlinf/models/embodiment/openvla_oft/rlinf/__init__.py +109 -0
- rlinf/models/embodiment/openvla_oft/rlinf/openvla_oft_action_model.py +574 -0
- rlinf/models/embodiment/prismatic/__init__.py +13 -0
- rlinf/models/embodiment/prismatic/processing_prismatic.py +243 -0
- rlinf/runners/__init__.py +13 -0
- rlinf/runners/agent_eval_runner.py +379 -0
- rlinf/runners/agent_runner.py +319 -0
- rlinf/runners/async_embodied_runner.py +181 -0
- rlinf/runners/coding_online_rl_runner.py +308 -0
- rlinf/runners/embodied_eval_runner.py +80 -0
- rlinf/runners/embodied_runner.py +291 -0
- rlinf/runners/reasoning_eval_runner.py +194 -0
- rlinf/runners/reasoning_runner.py +498 -0
- rlinf/runners/sft_runner.py +153 -0
- rlinf/scheduler/__init__.py +49 -0
- rlinf/scheduler/channel/__init__.py +18 -0
- rlinf/scheduler/channel/channel.py +645 -0
- rlinf/scheduler/channel/channel_worker.py +536 -0
- rlinf/scheduler/cluster/__init__.py +29 -0
- rlinf/scheduler/cluster/cluster.py +486 -0
- rlinf/scheduler/cluster/config.py +442 -0
- rlinf/scheduler/cluster/node.py +546 -0
- rlinf/scheduler/cluster/utils.py +221 -0
- rlinf/scheduler/collective/__init__.py +36 -0
- rlinf/scheduler/collective/async_work.py +386 -0
- rlinf/scheduler/collective/collective.py +96 -0
- rlinf/scheduler/collective/collective_group.py +1761 -0
- rlinf/scheduler/collective/multi_channel_pg.py +894 -0
- rlinf/scheduler/dynamic_scheduler/__init__.py +13 -0
- rlinf/scheduler/dynamic_scheduler/manager.py +1069 -0
- rlinf/scheduler/dynamic_scheduler/scheduler_worker.py +129 -0
- rlinf/scheduler/dynamic_scheduler/utils.py +162 -0
- rlinf/scheduler/hardware/__init__.py +36 -0
- rlinf/scheduler/hardware/accelerators/__init__.py +31 -0
- rlinf/scheduler/hardware/accelerators/accelerator.py +284 -0
- rlinf/scheduler/hardware/accelerators/amd_gpu.py +141 -0
- rlinf/scheduler/hardware/accelerators/ascend_npu.py +113 -0
- rlinf/scheduler/hardware/accelerators/intel_gpu.py +113 -0
- rlinf/scheduler/hardware/accelerators/musa_gpu.py +147 -0
- rlinf/scheduler/hardware/accelerators/nvidia_gpu.py +203 -0
- rlinf/scheduler/hardware/hardware.py +180 -0
- rlinf/scheduler/hardware/robots/__init__.py +17 -0
- rlinf/scheduler/hardware/robots/franka.py +176 -0
- rlinf/scheduler/manager/__init__.py +32 -0
- rlinf/scheduler/manager/coll_manager.py +140 -0
- rlinf/scheduler/manager/lock_manager.py +187 -0
- rlinf/scheduler/manager/manager.py +123 -0
- rlinf/scheduler/manager/node_manager.py +46 -0
- rlinf/scheduler/manager/worker_manager.py +315 -0
- rlinf/scheduler/placement/__init__.py +27 -0
- rlinf/scheduler/placement/flexible.py +277 -0
- rlinf/scheduler/placement/node.py +205 -0
- rlinf/scheduler/placement/packed.py +335 -0
- rlinf/scheduler/placement/placement.py +674 -0
- rlinf/scheduler/worker/__init__.py +24 -0
- rlinf/scheduler/worker/lock.py +103 -0
- rlinf/scheduler/worker/worker.py +1262 -0
- rlinf/scheduler/worker/worker_group.py +527 -0
- rlinf/utils/__init__.py +13 -0
- rlinf/utils/ckpt_convertor/__init__.py +13 -0
- rlinf/utils/ckpt_convertor/convert_openpi_jax_to_python.py +706 -0
- rlinf/utils/ckpt_convertor/fsdp_convertor/__init__.py +13 -0
- rlinf/utils/ckpt_convertor/fsdp_convertor/config/fsdp_model_convertor.yaml +27 -0
- rlinf/utils/ckpt_convertor/fsdp_convertor/convert_dcp_to_pt.py +58 -0
- rlinf/utils/ckpt_convertor/fsdp_convertor/convert_pt_to_hf.py +81 -0
- rlinf/utils/ckpt_convertor/fsdp_convertor/utils.py +197 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/__init__.py +13 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/config.py +208 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/convert_hf_to_mg.py +410 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/convert_hf_to_middle_file.py +503 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/convert_mg_to_middle_file.py +863 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/convert_middle_file_to_hf.py +726 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/convert_middle_file_to_mg.py +626 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/default_args.yaml +144 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/__init__.py +31 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/fp8_utils.py +135 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/mg_loader.py +171 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/mg_moe_groupgemm.py +198 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/mp_utils.py +61 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/safetensors_loader.py +116 -0
- rlinf/utils/ckpt_convertor/megatron_convertor/utils/tensor_operations.py +402 -0
- rlinf/utils/convertor/__init__.py +13 -0
- rlinf/utils/convertor/utils.py +637 -0
- rlinf/utils/data_iter_utils.py +692 -0
- rlinf/utils/data_process.py +90 -0
- rlinf/utils/distributed.py +1014 -0
- rlinf/utils/drq.py +109 -0
- rlinf/utils/flops.py +240 -0
- rlinf/utils/initialize.py +330 -0
- rlinf/utils/logging.py +20 -0
- rlinf/utils/metric_logger.py +121 -0
- rlinf/utils/metric_utils.py +342 -0
- rlinf/utils/nested_dict_process.py +110 -0
- rlinf/utils/omega_resolver.py +36 -0
- rlinf/utils/patcher.py +217 -0
- rlinf/utils/placement.py +449 -0
- rlinf/utils/profiler.py +242 -0
- rlinf/utils/resharding/__init__.py +13 -0
- rlinf/utils/resharding/mcore_weight_reshard.py +335 -0
- rlinf/utils/resharding/reshard_config.py +93 -0
- rlinf/utils/resharding/utils.py +332 -0
- rlinf/utils/runner_utils.py +82 -0
- rlinf/utils/timers.py +195 -0
- rlinf/utils/torch_functionals.py +32 -0
- rlinf/utils/train_utils.py +84 -0
- rlinf/utils/utils.py +507 -0
- rlinf/workers/__init__.py +13 -0
- rlinf/workers/actor/__init__.py +30 -0
- rlinf/workers/actor/async_fsdp_sac_policy_worker.py +137 -0
- rlinf/workers/actor/fsdp_actor_worker.py +1377 -0
- rlinf/workers/actor/fsdp_sac_policy_worker.py +748 -0
- rlinf/workers/actor/megatron_actor_worker.py +1543 -0
- rlinf/workers/agent/__init__.py +13 -0
- rlinf/workers/agent/agent_loop.py +246 -0
- rlinf/workers/agent/tool_worker.py +43 -0
- rlinf/workers/env/__init__.py +13 -0
- rlinf/workers/env/async_env_worker.py +131 -0
- rlinf/workers/env/env_worker.py +441 -0
- rlinf/workers/inference/__init__.py +13 -0
- rlinf/workers/inference/fsdp_inference_worker.py +146 -0
- rlinf/workers/inference/megatron_inference_worker.py +105 -0
- rlinf/workers/inference/utils.py +48 -0
- rlinf/workers/reward/__init__.py +13 -0
- rlinf/workers/reward/reward_worker.py +113 -0
- rlinf/workers/rollout/__init__.py +13 -0
- rlinf/workers/rollout/hf/__init__.py +13 -0
- rlinf/workers/rollout/hf/async_huggingface_worker.py +52 -0
- rlinf/workers/rollout/hf/huggingface_worker.py +404 -0
- rlinf/workers/rollout/hf/utils.py +30 -0
- rlinf/workers/rollout/server/__init__.py +13 -0
- rlinf/workers/rollout/server/online_router_worker.py +259 -0
- rlinf/workers/rollout/server/server_rollout_worker.py +379 -0
- rlinf/workers/rollout/sglang/__init__.py +43 -0
- rlinf/workers/rollout/sglang/sglang_worker.py +505 -0
- rlinf/workers/rollout/utils.py +562 -0
- rlinf/workers/rollout/vllm/__init__.py +41 -0
- rlinf/workers/rollout/vllm/vllm_worker.py +508 -0
- rlinf/workers/sft/__init__.py +13 -0
- rlinf/workers/sft/fsdp_sft_worker.py +175 -0
- rlinf-0.2.0.dev1.dist-info/METADATA +575 -0
- rlinf-0.2.0.dev1.dist-info/RECORD +356 -0
- rlinf-0.2.0.dev1.dist-info/WHEEL +5 -0
- rlinf-0.2.0.dev1.dist-info/licenses/LICENSE +201 -0
- rlinf-0.2.0.dev1.dist-info/top_level.txt +1 -0
rlinf/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright 2025 The RLinf Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .utils.omega_resolver import omegaconf_register
|
|
16
|
+
|
|
17
|
+
omegaconf_register()
|
rlinf/agents/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2025 The RLinf Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2025 The RLinf Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Copyright 2025 The RLinf Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import asyncio
|
|
17
|
+
|
|
18
|
+
from omegaconf import DictConfig
|
|
19
|
+
|
|
20
|
+
from rlinf.data.tool_call.tool_io_struct import ToolChannelRequest, ToolChannelResponse
|
|
21
|
+
from rlinf.scheduler import Channel
|
|
22
|
+
from rlinf.workers.agent.tool_worker import ToolWorker
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class FakeToolWorker(ToolWorker):
|
|
26
|
+
def __init__(self, cfg: DictConfig):
|
|
27
|
+
super().__init__()
|
|
28
|
+
self.cfg = cfg
|
|
29
|
+
self.request_processor_task = None
|
|
30
|
+
|
|
31
|
+
def init_worker(self, input_channel: Channel, output_channel: Channel):
|
|
32
|
+
self.input_channel = input_channel
|
|
33
|
+
self.output_channel = output_channel
|
|
34
|
+
|
|
35
|
+
def start_server(self):
|
|
36
|
+
loop = asyncio.get_running_loop()
|
|
37
|
+
self.request_processor_task = loop.create_task(self._process_requests())
|
|
38
|
+
|
|
39
|
+
def stop_server(self):
|
|
40
|
+
# Cancel request processor task
|
|
41
|
+
if self.request_processor_task and not self.request_processor_task.done():
|
|
42
|
+
self.request_processor_task.cancel()
|
|
43
|
+
|
|
44
|
+
async def _process_requests(self):
|
|
45
|
+
async def generate_and_send(session_id: str, tool_args: dict):
|
|
46
|
+
response = ToolChannelResponse(
|
|
47
|
+
success=True,
|
|
48
|
+
result="fake_tool_response",
|
|
49
|
+
)
|
|
50
|
+
await self.output_channel.put(
|
|
51
|
+
response, key=session_id, async_op=True
|
|
52
|
+
).async_wait()
|
|
53
|
+
self.logger.info("FakeToolWorker._process_requests: sent response")
|
|
54
|
+
|
|
55
|
+
while True:
|
|
56
|
+
request: ToolChannelRequest = await self.input_channel.get(
|
|
57
|
+
async_op=True
|
|
58
|
+
).async_wait()
|
|
59
|
+
self.logger.info("FakeToolWorker._process_requests: got request")
|
|
60
|
+
assert request.request_type == "execute"
|
|
61
|
+
assert request.tool_name == "fake_tool"
|
|
62
|
+
asyncio.create_task(
|
|
63
|
+
generate_and_send(request.session_id, request.tool_args)
|
|
64
|
+
)
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Copyright 2025 The RLinf Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
import copy
|
|
17
|
+
import json
|
|
18
|
+
import random
|
|
19
|
+
import time
|
|
20
|
+
from dataclasses import dataclass, field
|
|
21
|
+
from typing import Any
|
|
22
|
+
from uuid import uuid4
|
|
23
|
+
|
|
24
|
+
from omegaconf import DictConfig
|
|
25
|
+
|
|
26
|
+
from rlinf.data.tool_call.tool_io_struct import (
|
|
27
|
+
ToolChannelRequest,
|
|
28
|
+
ToolChannelResponse,
|
|
29
|
+
ToolRequest,
|
|
30
|
+
ToolResponse,
|
|
31
|
+
)
|
|
32
|
+
from rlinf.utils.placement import ModelParallelComponentPlacement
|
|
33
|
+
from rlinf.workers.agent.agent_loop import AgentLoopOutput, AgentLoopWorker
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class GenerateContext:
|
|
38
|
+
tool_session_ids: dict[str, str] = field(default_factory=dict)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class MCPAgentLoopWorker(AgentLoopWorker):
|
|
42
|
+
"""
|
|
43
|
+
An agent loop worker that can interact with mcp tools with session.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
cfg: DictConfig,
|
|
49
|
+
placement: ModelParallelComponentPlacement,
|
|
50
|
+
):
|
|
51
|
+
super().__init__(cfg, placement)
|
|
52
|
+
self.max_prompt_len = int(self.cfg.data.max_prompt_length)
|
|
53
|
+
max_total_len = int(self.cfg.actor.model.encoder_seq_length)
|
|
54
|
+
self.max_resp_len = max(1, max_total_len - self.max_prompt_len)
|
|
55
|
+
|
|
56
|
+
# 5 is a magic number in this demo.
|
|
57
|
+
self.max_turns = self.cfg.agentloop.get("max_turns", 5)
|
|
58
|
+
|
|
59
|
+
def generate_context_create(self) -> dict[str, Any]:
|
|
60
|
+
return GenerateContext()
|
|
61
|
+
|
|
62
|
+
async def generate_context_release(
|
|
63
|
+
self, generate_context: GenerateContext
|
|
64
|
+
) -> dict[str, Any]:
|
|
65
|
+
for tool_worker_name, session_id in generate_context.tool_session_ids.items():
|
|
66
|
+
if self.tool_channel_info_map[tool_worker_name].has_session:
|
|
67
|
+
# tool need session
|
|
68
|
+
await self.tool_session_release(tool_worker_name, session_id)
|
|
69
|
+
|
|
70
|
+
async def tool_session_get(
|
|
71
|
+
self, generate_context: GenerateContext, tool_name: str
|
|
72
|
+
) -> Any:
|
|
73
|
+
tool_worker_name = self.tool_name_map[tool_name]
|
|
74
|
+
tool_channel_info = self.tool_channel_info_map[tool_worker_name]
|
|
75
|
+
if tool_worker_name in generate_context.tool_session_ids:
|
|
76
|
+
return generate_context.tool_session_ids[tool_worker_name]
|
|
77
|
+
session_id = uuid4().hex
|
|
78
|
+
generate_context.tool_session_ids[tool_worker_name] = session_id
|
|
79
|
+
if tool_channel_info.has_session:
|
|
80
|
+
# tool need session
|
|
81
|
+
await tool_channel_info.input_channel.put(
|
|
82
|
+
ToolChannelRequest(session_id=session_id, request_type="session_start"),
|
|
83
|
+
async_op=True,
|
|
84
|
+
).async_wait()
|
|
85
|
+
response: ToolChannelResponse = await self.tool_worker_output_channel.get(
|
|
86
|
+
session_id, async_op=True
|
|
87
|
+
).async_wait()
|
|
88
|
+
assert response.success
|
|
89
|
+
return session_id
|
|
90
|
+
|
|
91
|
+
async def tool_session_release(self, tool_worker_name, session_id) -> str | dict:
|
|
92
|
+
tool_channel_info = self.tool_channel_info_map[tool_worker_name]
|
|
93
|
+
await tool_channel_info.input_channel.put(
|
|
94
|
+
ToolChannelRequest(session_id=session_id, request_type="session_end"),
|
|
95
|
+
async_op=True,
|
|
96
|
+
).async_wait()
|
|
97
|
+
response: ToolChannelResponse = await self.tool_worker_output_channel.get(
|
|
98
|
+
session_id, async_op=True
|
|
99
|
+
).async_wait()
|
|
100
|
+
assert response.success
|
|
101
|
+
|
|
102
|
+
async def tool_call(
|
|
103
|
+
self, generate_context: GenerateContext, tool_request: ToolRequest
|
|
104
|
+
) -> ToolResponse:
|
|
105
|
+
tool_name, tool_args = tool_request.name, tool_request.arguments
|
|
106
|
+
tool_channel_info = self.tool_channel_info_map[self.tool_name_map[tool_name]]
|
|
107
|
+
tool_input_channel = tool_channel_info.input_channel
|
|
108
|
+
session_id = await self.tool_session_get(generate_context, tool_name)
|
|
109
|
+
await tool_input_channel.put(
|
|
110
|
+
ToolChannelRequest(
|
|
111
|
+
session_id=session_id,
|
|
112
|
+
request_type="execute",
|
|
113
|
+
tool_name=tool_name,
|
|
114
|
+
tool_args=tool_args,
|
|
115
|
+
),
|
|
116
|
+
async_op=True,
|
|
117
|
+
).async_wait()
|
|
118
|
+
response: ToolChannelResponse = await self.tool_worker_output_channel.get(
|
|
119
|
+
session_id, async_op=True
|
|
120
|
+
).async_wait()
|
|
121
|
+
assert response.success
|
|
122
|
+
if isinstance(response.result, (list, dict)):
|
|
123
|
+
result_text = json.dumps(response.result)
|
|
124
|
+
else:
|
|
125
|
+
result_text = str(response.result)
|
|
126
|
+
return ToolResponse(
|
|
127
|
+
text=result_text,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
async def extract_tool_calls(self, response_text) -> tuple[str, list[ToolRequest]]:
|
|
131
|
+
# random tool call
|
|
132
|
+
return_function_calls = random.choice(
|
|
133
|
+
[
|
|
134
|
+
[
|
|
135
|
+
ToolRequest(
|
|
136
|
+
name="write_file",
|
|
137
|
+
arguments={
|
|
138
|
+
"path": "/projects/test/mcp_written.txt",
|
|
139
|
+
"content": f"Written by mcp at {time.strftime('%Y-%m-%d %H:%M:%S')}",
|
|
140
|
+
},
|
|
141
|
+
)
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
ToolRequest(
|
|
145
|
+
name="list_directory", arguments={"path": "/projects/test"}
|
|
146
|
+
)
|
|
147
|
+
],
|
|
148
|
+
]
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
return response_text, return_function_calls
|
|
152
|
+
|
|
153
|
+
async def run_one_query(self, prompt_ids: list[int]) -> AgentLoopOutput:
|
|
154
|
+
generate_context: GenerateContext = self.generate_context_create()
|
|
155
|
+
prompt_ids = prompt_ids[: self.max_prompt_len]
|
|
156
|
+
orig_prompt_ids = copy.deepcopy(prompt_ids)
|
|
157
|
+
trace_prints = []
|
|
158
|
+
response_mask = []
|
|
159
|
+
try:
|
|
160
|
+
for _ in range(self.max_turns):
|
|
161
|
+
# Generate response from LLM
|
|
162
|
+
generate_result = await self.generate(prompt_ids)
|
|
163
|
+
response_ids = generate_result["output_ids"]
|
|
164
|
+
max_resp_len = self.max_resp_len - (
|
|
165
|
+
len(prompt_ids) - len(orig_prompt_ids)
|
|
166
|
+
)
|
|
167
|
+
if len(response_ids) > max_resp_len:
|
|
168
|
+
response_ids = response_ids[:max_resp_len]
|
|
169
|
+
response_text = self.tokenizer.decode(response_ids)
|
|
170
|
+
prompt_ids += response_ids
|
|
171
|
+
response_mask += [1] * len(response_ids) # 1 for LLM generated tokens
|
|
172
|
+
if self.print_outputs:
|
|
173
|
+
# add anything you want to print
|
|
174
|
+
trace_prints.append({"generate": response_text})
|
|
175
|
+
if len(response_ids) == max_resp_len:
|
|
176
|
+
break
|
|
177
|
+
|
|
178
|
+
# Extract tool calls from response
|
|
179
|
+
_, tool_requests = await self.extract_tool_calls(response_text)
|
|
180
|
+
|
|
181
|
+
# Execute tools in parallel with history propagation
|
|
182
|
+
tasks = []
|
|
183
|
+
for tool_request in tool_requests:
|
|
184
|
+
tasks.append(self.tool_call(generate_context, tool_request))
|
|
185
|
+
tool_responses: list[ToolResponse] = await asyncio.gather(*tasks)
|
|
186
|
+
|
|
187
|
+
# Convert tool responses to messages and tokenize
|
|
188
|
+
tool_messages = []
|
|
189
|
+
for tool_response in tool_responses:
|
|
190
|
+
message = {"role": "tool", "content": tool_response.text}
|
|
191
|
+
tool_messages.append(message)
|
|
192
|
+
|
|
193
|
+
# Tokenize tool responses
|
|
194
|
+
tool_response_ids = self.get_tool_response_ids(tool_messages)
|
|
195
|
+
max_tool_resp_len = self.max_resp_len - (
|
|
196
|
+
len(prompt_ids) - len(orig_prompt_ids)
|
|
197
|
+
)
|
|
198
|
+
if len(tool_response_ids) > max_tool_resp_len:
|
|
199
|
+
break
|
|
200
|
+
|
|
201
|
+
prompt_ids += tool_response_ids
|
|
202
|
+
response_mask += [0] * len(
|
|
203
|
+
tool_response_ids
|
|
204
|
+
) # 0 for tool response tokens
|
|
205
|
+
if self.print_outputs:
|
|
206
|
+
# add anything you want to print
|
|
207
|
+
trace_prints[-1]["tool_resp"] = tool_messages
|
|
208
|
+
|
|
209
|
+
# Separate prompt and response
|
|
210
|
+
response_ids = prompt_ids[len(orig_prompt_ids) :]
|
|
211
|
+
|
|
212
|
+
return AgentLoopOutput(
|
|
213
|
+
prompt_ids=orig_prompt_ids,
|
|
214
|
+
prompt_text=self.tokenizer.decode(orig_prompt_ids),
|
|
215
|
+
response_ids=response_ids,
|
|
216
|
+
response_text=self.tokenizer.decode(response_ids),
|
|
217
|
+
response_mask=response_mask,
|
|
218
|
+
trace_prints=trace_prints,
|
|
219
|
+
)
|
|
220
|
+
finally:
|
|
221
|
+
await self.generate_context_release(generate_context)
|