instruction
stringclasses
100 values
code
stringlengths
78
193k
response
stringlengths
259
170k
file
stringlengths
59
203
Write documentation strings for class attributes
# Copyright 2025 Bytedance Ltd. and/or its affiliates # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or ...
--- +++ @@ -20,6 +20,7 @@ class DatasetPadMode(str, Enum): + """Padding mode for dataset""" RIGHT = "right" LEFT_RIGHT = "left_right" @@ -27,6 +28,11 @@ class SFTTensorCollator: + """ + A custom collate_fn that handles batching of sequences. + 1. for variable-length sequences, convert th...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/dataset/dataset_utils.py
Add return value explanations in docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,54 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Rollout Correction Helper Module + +This module provides a complete pipeline to address **off-policy issues...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/trainer/ppo/rollout_corr_helper.py
Add docstrings explaining edge cases
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -21,6 +21,7 @@ def build_position_ids_for_prefix_grouper(prefix_grouper: PrefixGrouper) -> torch.Tensor: + """Build position_ids for PrefixGrouper where each response restarts from prefix_len.""" num_samples = len(prefix_grouper.group_info) max_len = prefix_grouper.padding_mask.size(1) ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/trainer/ppo/prefix_grouper_utils.py
Add detailed documentation for each class
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at #...
--- +++ @@ -13,6 +13,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +PPO Trainer with Ray-based single controller. +This trainer supports model-agonistic model initialization w...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/trainer/ppo/ray_trainer.py
Add docstrings explaining edge cases
# Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # ...
--- +++ @@ -29,8 +29,35 @@ class Gsm8kTool(BaseTool): + """A demo tool for calculating the reward of gsm8k. + + - `get_openai_tool_schema`: return the tool schema in OpenAI format. + - `create`: create a tool instance for a trajectory. + - `execute`: execute the tool. + - `calc_reward`: calculate the...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/tools/gsm8k_tool.py
Write documentation strings for class attributes
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for distributed training.""" import ctypes import os @@ -92,6 +93,13 @@ def stateless_init_p...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/distributed.py
Add docstrings for production code
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # This code is inspired by the torchtune. # https://github.com/pytorch/torchtune/blob/main/torchtune/utils/_device.py # # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license in http...
--- +++ @@ -20,6 +20,17 @@ def is_torch_npu_available(check_device=True) -> bool: + """Check if Ascend NPU is available for PyTorch operations. + + Attempts to detect NPU availability by checking for the torch.npu module + and its is_available() function. + + Args: + check_device : only check tor...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/device.py
Include argument descriptions in docstrings
#!/usr/bin/env python # Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless requi...
--- +++ @@ -14,6 +14,7 @@ # limitations under the License. # -*- coding: utf-8 -*- +"""File-system agnostic IO APIs""" import hashlib import os @@ -31,14 +32,45 @@ def is_non_local(path): + """Check if a path is a non-local (HDFS) path. + + Args: + path (str): The path to check. + + Returns: ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/fs.py
Add docstrings to make code maintainable
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -80,6 +80,11 @@ def initialize_tools_from_config(tools_config_file): + """Initialize tools from config file. + + Supports both NATIVE and MCP tool types. For MCP tools, a temporary event loop + is created only when needed and properly closed after use to prevent memory leaks. + """ tools...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/tools/utils/tool_registry.py
Write docstrings for data processing functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Note that we don't combine the main with ray_trainer as ray_trainer is used by other mpain. +""" import o...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/trainer/main_ppo.py
Add docstrings including usage examples
# # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # ...
--- +++ @@ -28,6 +28,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Implementations of the linear cross entropy with token entropy kernel. +""" import typing from dataclass...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/kernel/kernels.py
Create docstrings for reusable components
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -41,6 +41,21 @@ def get_device_flops(unit="T", device_name=None): + """Get the theoretical FLOPS (Floating Point Operations Per Second) capacity of the current device. + + Args: + unit (str): The unit to return the FLOPS in. Supported values are: + "B" - Billion (1e9) + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/flops_counter.py
Generate consistent docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -39,10 +39,12 @@ def ceil_div(x: int, y: int) -> int: + """Perform ceiling division of two integers.""" return (x + y - 1) // y def is_triton_available() -> bool: + """Check if Triton is available for FP8 kernels.""" return _TRITON_AVAILABLE @@ -67,6 +69,13 @@ BLOCK_M: tl...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/kernel/fp8_kernel.py
Document this code for team use
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -25,18 +25,44 @@ def exists(path: str, **kwargs) -> bool: + r"""Works like os.path.exists() but supports hdfs. + + Test whether a path exists. Returns False for broken symbolic links. + + Args: + path (str): path to test + + Returns: + bool: True if the path exists, False otherw...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/hdfs_io.py
Add professional docstrings to my codebase
# Copyright 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -29,6 +29,14 @@ self.quant_config = quant_config def should_quantize_param(self, param_name): + """Determine whether to quantize to FP8 based on parameter name + + Quantization rules: + - Must end with .weight (exclude bias) + - Exclude embedding layers + - E...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/fp8_utils.py
Add detailed docstrings explaining each function
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at #...
--- +++ @@ -14,6 +14,29 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Group-wise helpers for RL training utilities. + +Public API: + - as_torch_index(index, device=None) -> torch.LongTensor + - group_mean_std(scores, gidx, eps=1e-6, device=None)...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/groupwise.py
Add docstrings to make code maintainable
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -22,6 +22,16 @@ @dataclass class KLControlConfig(BaseConfig): + """Configuration for KL control. + + The inheritance from BaseConfig provides omegaconf.DictConfig-like interface for a dataclass config. + + Args: + type (str): Type of KL control. Can be "fixed" or "adaptive". + kl_co...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/trainer/config/algorithm.py
Create structured documentation for my script
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -74,6 +74,13 @@ # Copyright 2020-present the HuggingFace Inc. team. # Adapted from https://github.com/huggingface/transformers/src/transformers/trainer.py def get_fsdp_wrap_policy(module, config=None, is_lora=False): + """Get FSDP wrap policy for the module. + + Args: + module: The module to g...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/fsdp_utils.py
Generate docstrings for each module
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -22,6 +22,16 @@ @dataclass class CheckpointConfig(BaseConfig): + """Configuration for model checkpointing. + + The inheritance from BaseConfig provides omegaconf.DictConfig-like interface for a dataclass config. + + Args: + save_contents (list[str]): What to include in saved checkpoints. +...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/trainer/config/config.py
Add docstrings for better understanding
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Utilities to check if packages are available. +We assume package availability won't change during runtime. ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/import_utils.py
Fully document this Python code with docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. # Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in complianc...
--- +++ @@ -14,6 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Pretrain utilities.""" import gc import inspect @@ -60,6 +61,7 @@ transformer_config=None, overri...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/megatron_utils.py
Add clean documentation to messy code
# Copyright 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -29,6 +29,14 @@ def aggressive_empty_cache(force_sync: bool = True, max_retries: int = 3) -> None: + """ + More aggressive GPU memory cleanup function, tries to release PyTorch reserved + but unallocated memory. + + Args: + force_sync: Whether to force device synchronization + m...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/memory_utils.py
Provide clean and structured docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Utilities for PEFT (Parameter-Efficient Fine-Tuning) of Megatron in VERL.""" import os from pathlib import...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/megatron_peft_utils.py
Create documentation for each function signature
# Copyright 2023-2024 SGLang Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writin...
--- +++ @@ -29,6 +29,15 @@ def is_ipv4(ip_str: str) -> bool: + """ + Check if the given string is an IPv4 address + + Args: + ip_str: The IP address string to check + + Returns: + bool: Returns True if it's an IPv4 address, False otherwise + """ try: ipaddress.IPv4Address(...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/net_utils.py
Generate descriptive docstrings automatically
# Copyright 2024 PRIME team and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or a...
--- +++ @@ -11,6 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Answer checker API that uses sympy to simplify expressions and check for equality. + +Call grade_answer(giv...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/prime_math/__init__.py
Can you add docstrings to this Python file?
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -12,6 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Fast NVFP4 Quantizer for verl FSDP training. + +Directly computes scales and quantizes weights using compressed_tensors APIs. +Includes scale computation utilities for weight quanti...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/qat/quantizer.py
Turn comments into proper docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law o...
--- +++ @@ -79,6 +79,15 @@ # Copied from https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/bert_padding.py def pad_input(hidden_states, indices, batch, seqlen): + """ + Arguments: + hidden_states: (total_nnz, ...), where total_nnz = number of tokens in selected in attention_mask. + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/npu_flash_attn_utils.py
Improve documentation using docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -77,6 +77,9 @@ optimizer, config, ): + """ + Get the optimizer parameter scheduler for Megatron. + """ lr_decay_steps = config.lr_decay_steps lr_warmup_steps = config.lr_warmup_steps if config.get("lr_decay_steps", None) is None: @@ -111,4 +114,7 @@ def get_megatron_last...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/megatron/optimizer.py
Document all public functions with docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -55,6 +55,58 @@ class MegatronCheckpointManager(BaseCheckpointManager): + """ + Checkpoint manager for Megatron-LM distributed training. + + This class manages the saving and loading of model checkpoints in a Megatron-LM + distributed training environment. It handles various aspects of checkp...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/checkpoint/megatron_checkpoint_manager.py
Write docstrings describing functionality
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -43,12 +43,36 @@ @dataclass class FSDPConfig: + """Configuration for FSDP checkpointing. + + Args: + FSDP_version (int): Version of FSDP being used. + world_size (int): Number of processes in the distributed training setup. + """ FSDP_version: int world_size: int cl...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/checkpoint/fsdp_checkpoint_manager.py
Generate docstrings for script automation
# Copyright 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # ...
--- +++ @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Functionality for CPU offloading of tensors saved for backward pass.""" from __future__ import annotations @@ -51,6 +52,12 @@ class CpuOffloadHookWithOffloadHandler: + """C...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/activation_offload.py
Add verbose docstrings with examples
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -28,14 +28,32 @@ def mark_start_range(message: Optional[str] = None) -> None: + """Start a mark range in the profiler. + + Args: + message (str, optional): + The message to be displayed in the profiler. Defaults to None. + """ return mstx.range_start(message=message) ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/profiler/mstx_profile.py
Add docstrings to improve collaboration
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -30,10 +30,28 @@ domain: Optional[str] = None, category: Optional[str] = None, ) -> None: + """Start a mark range in the profiler. + + Args: + message (str, optional): + The message to be displayed in the profiler. Defaults to None. + color (str, optional): + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/profiler/nvtx_profile.py
Create simple docstrings for beginners
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -12,6 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Router Replay Utilities +Utilities for handling router replay functionality in Megatron models. +""" import inspect import warnings @@ -47,6 +51,16 @@ def get_num_layers_to_buil...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/megatron/router_replay_utils.py
Help me write clear docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -12,6 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +vLLM NVFP4 Patches for Dynamic Weight Updates. + +Enables dynamic weight reloading for NVFP4 quantized models in vLLM. + +Supported schemes: +- Dense: W4A16-FP4, W4A4-FP4 +- MoE: NV...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/qat/vllm_patch.py
Expand my code with proper documentation strings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -18,6 +18,7 @@ def _get_attention_functions() -> tuple[Callable, Callable, Callable, Callable]: + """Dynamically import attention functions based on available hardware.""" from verl.utils.device import is_torch_npu_available @@ -34,23 +35,66 @@ def index_first_axis(*args, **kwargs): + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/attention_utils.py
Add concise docstrings to each method
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -19,6 +19,12 @@ def match_score(list1, list2): + """Compute a similarity score considering element frequency, ignoring order. + + Reference: Liu S Y, Dong X, Lu X, et al. "Gdpo: Group reward-decoupled normalization policy + optimization for multi-reward rl optimization." + arXiv preprint arXi...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/rlla.py
Can you add docstrings to this Python file?
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -21,6 +21,17 @@ def omega_conf_to_dataclass(config: DictConfig | dict, dataclass_type: Optional[type[Any]] = None) -> Any: + """ + Convert an OmegaConf DictConfig to a dataclass. + + Args: + config: The OmegaConf DictConfig or dict to convert. + dataclass_type: The dataclass type t...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/config.py
Document helper functions with docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -65,6 +65,19 @@ class Profiler(DistProfiler): + """A PyTorch profiler wrapper class for collecting performance metrics. + + This profiler provides a convenient interface for profiling PyTorch operations, + with support for: + + - CPU and CUDA activity profiling + - Configurable profiling s...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/profiler/torch_profile.py
Expand my code with proper documentation strings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""QAT (Quantization-Aware Training) utilities for verl FSDP training.""" import json import logging @@ -28,6 +29,7 @@ @dataclass class QATConfig(BaseConfig): + """Unified confi...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/qat/core.py
Add docstrings that explain logic
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Utilities to create common models from huggingface +""" import json import os @@ -68,6 +71,11 @@ def...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/model.py
Add docstrings for production code
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -12,6 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""QAT FakeQuantized Linear module for NVFP4 (W4A4/W4A16) with FSDP compatibility. + +Includes Triton kernels for high-performance FP4 quantization. +""" from enum import Enum from t...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/qat/linear.py
Document this script properly
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by appli...
--- +++ @@ -85,6 +85,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +This logic is largely copied from the Hendrycks' MATH release (math_equivalence), and borrowed from: +- htt...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/prime_math/grader.py
Please document this code using docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Metrics utils. +""" from enum import Enum from typing import Any, Optional, Union @@ -20,6 +23,29 @@ ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/metric/utils.py
Create docstrings for API functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +A Ray logger will receive logging info from different processes. +""" import datetime import logging @@ ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/logger/aggregate_logger.py
Create docstrings for reusable components
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -42,12 +42,23 @@ class RouterReplay: + """ + A class to manage the recording and replaying of MoE routing decisions. + It holds all router instances and provides static methods to globally + control recording and replaying. + """ # Static variable to hold all router instances, one p...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/megatron/router_replay_patch.py
Add docstrings that explain logic
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # htt...
--- +++ @@ -18,6 +18,14 @@ def last_boxed_only_string(string: str) -> Optional[str]: + """Extract the last LaTeX boxed expression from a string. + + Args: + string: Input string containing LaTeX code + + Returns: + The last boxed expression or None if not found + """ idx = string.rfin...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/math_dapo.py
Add docstrings to my Python code
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -25,10 +25,23 @@ domain: Optional[str] = None, category: Optional[str] = None, ) -> None: + """Start a profiling range marker (no-op implementation). + + Args: + message (Optional[str]): Message to associate with the range marker. + color (Optional[str]): Color for the marker vi...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/profiler/profile.py
Write docstrings including parameters and return values
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -73,6 +73,23 @@ memory_limit_mb: int, language: str = "python", ) -> tuple[Optional[dict[str, Any]], Optional[str]]: # <-- Remove request_id parameter + """ + Calls the remote sandbox API to execute code with retry logic for Gateway Timeout, + using increasing delay between retries. Logs ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/sandbox_fusion/utils.py
Provide docstrings following PEP 257
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Contain small python utility functions +""" import importlib import multiprocessing @@ -30,6 +33,10 @@ #...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/py_functional.py
Add docstrings to clarify complex logic
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Contains commonly used utilities for ray +""" import asyncio import concurrent.futures @@ -46,6 +49,18 @...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/ray_utils.py
Write docstrings for backend logic
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -27,6 +27,18 @@ def _get_current_mem_info(unit: str = "GB", precision: int = 2) -> tuple[str]: + """Get current memory usage. + + Note that CPU device memory info is always 0. + + Args: + unit (str, optional): The unit of memory measurement. Defaults to "GB". + precision (int, opti...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/profiler/performance.py
Help me write clear docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -12,6 +12,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Utilities for using tensor_parallel in megatron +""" from typing import TYPE_CHECKING @@ -137,16 +140,3...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/megatron/tensor_parallel.py
Write docstrings including parameters and return values
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -25,6 +25,7 @@ @dataclass class NsightToolConfig(BaseConfig): + """Nsight tool config.""" "True for each task has its own database, False for all tasks in one training step share one database." discrete: bool = False @@ -36,6 +37,7 @@ @dataclass class TorchProfilerToolConfig(BaseConfig):...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/profiler/config.py
Create docstrings for all classes and functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at #...
--- +++ @@ -13,6 +13,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Single Process Actor +""" import logging import os @@ -44,8 +47,16 @@ class DataParallelPPOActor(Bas...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/actor/dp_actor.py
Write clean docstrings for readability
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -26,6 +26,21 @@ memory_limit_mb=None, **kwargs, ): + """Compute the score for a given solution based on the data source. + + Args: + data_source (str): The source dataset identifier which determines the scoring method. + solution_str (str): The solution string to be evaluated. +...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/__init__.py
Add docstrings for production code
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -27,6 +27,22 @@ class RolloutTraceConfig: + """Configuration for rollout tracing with various backends. + + Singleton configuration class for managing rollout trace settings across different + tracing backends like Weave and MLflow. + + Args: + backend (Optional[str]): Tracing backend ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/rollout_trace.py
Generate consistent documentation across files
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Megatron Actor. +In megatron actor, the differences are: +1. We only make minibatch + +Note that our model ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/actor/megatron_actor.py
Create docstrings for all classes and functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -40,12 +40,28 @@ @dataclass class RouterReplayConfig(BaseConfig): + """Configuration for router replay in MoE models. + + This configuration controls the routing behavior for Mixture of Experts (MoE) models, + allowing for deterministic training through route recording and replay. + + Args: + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/actor.py
Add docstrings following best practices
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -25,10 +25,49 @@ def calculate_workload(seqlen_list: torch.Tensor) -> torch.Tensor: + """Calculate approximate computational workload for transformer attention. + + Estimates FLOPs for dense transformer blocks based on sequence length using + the formula: FLOPs ≈ 12 * hidden_size² * seqlen + 2 *...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/seqlen_balancing.py
Create docstrings for reusable components
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -31,6 +31,15 @@ @dataclass class OptimizerConfig(BaseConfig): + """Base optimizer configuration. + + Args: + lr (float): learning rate. Must be specified. + lr_warmup_steps_ratio (float): Warmup steps ratio; total steps will be injected at runtime. + total_training_steps (int): ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/optimizer.py
Generate NumPy-style docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -21,11 +21,48 @@ def assign_non_tensor_data(tensor_dict: TensorDict, key, val): + """Assign a single non-tensor value to a TensorDict. + + Wraps the value in NonTensorData so it can be stored alongside tensors + in the TensorDict. Use this for scalar metadata or simple non-tensor values. + + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/tensordict_utils.py
Help me add docstrings to my project
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -93,6 +93,9 @@ @dataclass class ServerConfig(BaseConfig): + """ + Configuration for SGLang server when running in server mode + """ timeout: float = 60.0 max_attempts: int = 3 @@ -103,6 +106,9 @@ @dataclass class PrometheusConfig(BaseConfig): + """ + Configuration for Prometh...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/rollout.py
Can you add docstrings to this Python file?
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -30,6 +30,19 @@ @dataclass class RewardManagerConfig(BaseConfig): + """Configuration for reward manager. + + A reward manager defines the mechanism of computing rule-based reward and handling different reward sources. + + Args: + source (str): Source of the reward manager. Options: ``"...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/reward.py
Create docstrings for API functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Compatibility utilities for different versions of transformers library. +""" import importlib.metadata from functools import lru_cache @@ -27,6 +30,9 @@ # For older versions ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/transformers_compat.py
Add minimal docstrings for each function
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Contain small torch utilities +""" import math from contextlib import contextmanager @@ -44,11 +47,45 @@...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/torch_functional.py
Improve my code by adding docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Utilities for DeepSpeed Ulysses Sequence Parallelism. +DeepSpeed Ulysses Paper: https://arxiv.org/abs/2309....
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/ulysses.py
Add docstrings that explain logic
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The concrete Engine implementation using PyTorch FullyShardedDataParallel (FSDP) +""" import gc import l...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/engine/fsdp/transformer_impl.py
Add docstrings for internal functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The abstract base class defining the interface for model training engines. +""" from abc import abstractm...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/engine/base.py
Add docstrings that explain logic
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The main entry point to run the PPO algorithm +""" import datetime import logging @@ -243,6 +246,10 @@ ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/megatron_workers.py
Create simple docstrings for beginners
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -378,12 +378,29 @@ log_gpu_memory_usage("After offload model/optimizer/grad during init", logger=logger) def train_mode(self, **kwargs): + """ + Context manager entry for switching the engine and model into training mode. + + Usage: + with engine.train_mode(): +...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/engine/megatron/transformer_impl.py
Write reusable docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -24,6 +24,7 @@ def apply_npu_fsdp_patches(): + """Apply NPU patches for FSDP backend if NPU is available.""" if is_npu_available: try: import verl.models.transformers.npu_patch # noqa @@ -35,6 +36,16 @@ def create_device_mesh(world_size, fsdp_size): + """ + Create...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/engine/fsdp/utils.py
Improve documentation using docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,9 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""PEFT configuration of Megatron for VERL.""" def get_peft_cls(model_config, bridge, provider, dtype=None)...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/megatron_peft.py
Add docstrings to improve collaboration
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +"""Utils for tokenization.""" import types import warnings @@ -19,6 +20,11 @@ def normalize_token_ids(tok...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/tokenizer.py
Write proper docstrings for these functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The main entry point to run the PPO algorithm +""" import datetime import json @@ -125,6 +128,9 @@ d...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/fsdp_workers.py
Generate docstrings for script automation
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -38,12 +38,28 @@ # TODO: rename to RouterReplayConfig after removing the legacy implementation @dataclass class EngineRouterReplayConfig(BaseConfig): + """Configuration for router replay in MoE models. + + This configuration controls the routing behavior for Mixture of Experts (MoE) models, + allo...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/engine.py
Document this code for team use
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023-2024 SGLang Team # Copyright 2025 Search-R1 Contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://...
--- +++ @@ -1,137 +1,156 @@-# Copyright 2024 Bytedance Ltd. and/or its affiliates -# Copyright 2023-2024 SGLang Team -# Copyright 2025 Search-R1 Contributors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/reward_score/search_r1_like_qa_em.py
Generate docstrings with examples
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -31,6 +31,29 @@ @dataclass class CriticConfig(BaseConfig): + """Configuration for critic model training. + + The inheritance from BaseConfig provides omegaconf.DictConfig-like interface for a dataclass config. + + Args: + strategy (str): Strategy used for critic model training (fsdp, fsdp2...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/config/critic.py
Improve documentation using docstrings
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -22,6 +22,12 @@ def register(name: str) -> Callable[[type[AbstractRewardManager]], type[AbstractRewardManager]]: + """Decorator to register a reward manager class with a given name. + + Args: + name: `(str)` + The name of the reward manager. + """ def decorator(cls: type...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/reward_manager/registry.py
Write docstrings describing functionality
# Copyright 2024 PRIME team and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or a...
--- +++ @@ -101,6 +101,9 @@ @register("prime") class PrimeRewardManager(AbstractRewardManager): + """ + The Reward Manager used in https://github.com/PRIME-RL/PRIME + """ def __init__( self, @@ -115,6 +118,9 @@ self.reward_fn_key = reward_fn_key def verify(self, data): + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/reward_manager/prime.py
Generate docstrings with examples
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -25,14 +25,26 @@ @register("naive") class NaiveRewardManager(AbstractRewardManager): + """The reward manager.""" def __init__(self, tokenizer, num_examine, compute_score=None, reward_fn_key="data_source") -> None: + """ + Initialize the NaiveRewardManager instance. + + Args:...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/reward_manager/naive.py
Improve my code by adding docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +A unified tracking interface that supports logging data to different backend +""" import dataclasses imp...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/tracking.py
Generate descriptive docstrings automatically
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The base class for Actor +""" from abc import ABC, abstractmethod @@ -23,13 +26,41 @@ class BasePPOAc...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/actor/base.py
Generate descriptive docstrings automatically
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -68,6 +68,27 @@ class RolloutReplica(ABC): + """Rollout replica is an individual server instance, which may be deployed on single or multiple nodes. + It is equivalent to launch server in each node with command line: + + SGLang: + ``` + python -m sglang.launch_server --node-rank 0 --nnode ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/replica.py
Add well-formatted docstrings
# Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # ...
--- +++ @@ -35,6 +35,7 @@ class FinishReasonTypeEnum(str, Enum): + """The enum for finish reason type.""" LENGTH = "length" STOP = "stop" @@ -59,6 +60,7 @@ class AsyncRolloutRequestStateEnum(str, Enum): + """The enum for async rollout request state.""" PENDING = "pending" RUNNING =...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/schemas.py
Add documentation for all methods
# Copyright 2023-2024 SGLang Team # Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # ...
--- +++ @@ -57,6 +57,19 @@ class SGLangHttpServer: + """SGLang http server in single node, this is equivalent to launch server with command line: + ``` + python -m sglang.launch_server --node-rank 0 --nnode 1 ... + ``` + + Args: + config (DictConfig): full config. + rollout_mode (Rollou...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/sglang_rollout/async_sglang_server.py
Add professional docstrings to my codebase
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -37,6 +37,14 @@ @staticmethod def hijack(): def hijack__load_adapter(self, lora_request: TensorLoRARequest) -> LoRAModel: + """ + based on vllm.lora.worker_manager.WorkerLoRAManager._load_adapter, support load adapter with lora tensors + + Reason: + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/vllm/utils.py
Document this script properly
# Copyright 2025 Bytedance Ltd. and/or its affiliates # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache....
--- +++ @@ -102,6 +102,18 @@ def quant_weights(weights, model, quant_config, dtype=torch.bfloat16): + """Quantize weights to FP8 format using a memory-efficient generator. + + + Args: + weights: Generator or iterable of (name, tensor) pairs + model: The model to check for FP8 weight names + ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/utils/vllm/vllm_fp8_utils.py
Include argument descriptions in docstrings
# Copyright 2026 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -50,6 +50,11 @@ @contextlib.contextmanager def nvml_context(): + """Context manager for NVML initialization and shutdown. + + Raises: + RuntimeError: If NVML initialization fails + """ try: pynvml.nvmlInit() yield @@ -67,6 +72,7 @@ def get_device_uuid(id: str | i...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/trtllm_rollout/trtllm_rollout.py
Add concise docstrings to each method
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Bucketed weight transfer via ZMQ + IPC (or shared memory fallback). + +Not recommended depending on vllm fo...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/vllm_rollout/bucketed_weight_transfer.py
Create docstrings for reusable components
# Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at #...
--- +++ @@ -86,6 +86,12 @@ # because chatCompletion is an async method, it makes the whole ray actor be an async actor # which can not call loop.run_until_complete. So we need to make the engine to be an async class class ServerAdapter(BaseRollout): + """SGLang server adapter used in native http server mode, serve...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/sglang_rollout/sglang_rollout.py
Add docstrings for internal functions
# Copyright 2026 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -37,6 +37,19 @@ @ray.remote class TRTLLMHttpServer: + """TensorRT LLM HTTP server in single node. + + Args: + config (DictConfig): full config. + model_config (HFModelConfig): model config. + is_reward_model (bool): whether this is a reward model. + rollout_mode (RolloutM...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/trtllm_rollout/trtllm_async_server.py
Add docstrings that explain inputs and outputs
# Copyright 2023-2024 SGLang Team # Copyright 2025 ModelBest Inc. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # ...
--- +++ @@ -31,6 +31,12 @@ src: int = 0, force_cpu_device: bool = False, ): + """from https://github.com/sgl-project/sglang/blob/844e2f227ab0cce6ef818a719170ce37b9eb1e1b/python/sglang/srt/utils.py#L905 + + Broadcast inputs from src rank to all other ranks with torch.dist backend. + The `rank` here re...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/sglang_rollout/utils.py
Document classes and their methods
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The base tokenizer class, required for any hybrid engine based rollout or inference with vLLM. +""" from ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/tokenizer.py
Generate docstrings with examples
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +The concrete Engine implementation using PyTorch TorchTitan parallelism (FSDP2 + TP + PP) +""" import gc ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/engine/torchtitan/transformer_impl.py
Generate consistent docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -11,6 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +""" +Implement a multiprocess PPOCritic +""" import itertools import logging @@ -76,6 +79,7 @@ ) ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/critic/megatron_critic.py
Create Google-style docstrings for my code
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -27,6 +27,7 @@ class BaseRollout(ABC): + """Base class for rollout.""" def __init__( self, @@ -42,6 +43,11 @@ @abstractmethod async def resume(self, tags: list[str]): + """Resume rollout weights or kv cache in GPU memory. + + Args: + tags: weights or...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/base.py
Can you add docstrings to this Python file?
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -56,6 +56,15 @@ def _slice_response_from_unpad_output(tensor: torch.Tensor, data: TensorDict) -> torch.Tensor: + """Slice response from unpad model output. + + Args: + tensor: model output tensor of shape [bsz, 1] + data: TensorDict with "prompt_ids", "response_ids", "attention_mask" ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/utils/losses.py
Document this script properly
# Copyright 2024 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -34,6 +34,7 @@ class _UvicornServerAutoPort(uvicorn.Server): + """Uvicorn Server that reports the system-assigned port when port=0.""" def __init__(self, config: uvicorn.Config) -> None: super().__init__(config) @@ -73,6 +74,7 @@ async def ensure_async_iterator(iterable): + """C...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/rollout/utils.py
Document functions with detailed explanations
# Copyright 2025 Bytedance Ltd. and/or its affiliates # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law ...
--- +++ @@ -21,6 +21,21 @@ def left_right_2_no_padding(data: TensorDict) -> TensorDict: + """ + Convert TensorDict from left-right padding to no-padding format. + + Args: + data: TensorDict with "input_ids", "attention_mask", "response_mask", "position_ids" + + Returns: + data: TensorDict ...
https://raw.githubusercontent.com/verl-project/verl/HEAD/verl/workers/utils/padding.py