instruction
stringclasses
100 values
code
stringlengths
78
193k
response
stringlengths
259
170k
file
stringlengths
59
203
Document this module using docstrings
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -29,6 +29,26 @@ class KimiK2TikTokenTokenizer(PreTrainedTokenizer): + """ + Tokenizing and encoding/decoding text using the Tiktoken tokenizer. See megatron/tokenizer/tiktoken_tokenizer.py. + This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users shou...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/kimi_k2/tokenizer.py
Add detailed documentation for each class
# coding=utf-8 # Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. # Copyright 2026 The Moonshot AI Inc. team and 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 obtai...
--- +++ @@ -13,12 +13,25 @@ # 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. +"""processor class for Kimi-K2.5.""" from ..image_processing_utils import BatchFeature from ..processing_ut...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/kimi_k25/processor.py
Replace inline comments with docstrings
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -43,6 +43,9 @@ class Gemma3TextScaledWordEmbedding(nn.Embedding): + """ + This module overrides nn.Embeddings' forward by multiplying with embeddings scale. + """ def __init__(self, config): num_embeddings = config.vocab_size @@ -132,6 +135,17 @@ config: Optional[Gemma3Te...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/gemma3_text/modeling.py
Help me document legacy Python code
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -22,16 +22,37 @@ class NewGELUActivation(nn.Layer): - - def forward(self, input: Tensor) -> Tensor: + """ + Implementation of the GELU activation function currently in Google BERT repo (identical to OpenAI GPT). Also see + the Gaussian Error Linear Units paper: https://arxiv.org/abs/1606.0841...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/dfnrope/activation.py
Write docstrings including parameters and return values
# coding=utf-8 # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. # Copyright 2022 The HuggingFace Inc. 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.a...
--- +++ @@ -38,6 +38,17 @@ class PaddleImageProcessingMixin: + """ + A mixin that extends Hugging Face image processor classes to support + PaddlePaddle tensor return types. + + This mixin dynamically wraps common preprocessing and transformation + methods, enabling them to return Paddle tensors when...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/image_processing_utils.py
Write docstrings for data processing functions
# coding=utf-8 # Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. # Copyright 2026 The Moonshot AI Inc. team and 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 obtai...
--- +++ @@ -32,6 +32,26 @@ class TikTokenTokenizer(PreTrainedTokenizer): + """ + Tokenizing and encoding/decoding text using the Tiktoken tokenizer. See megatron/tokenizer/tiktoken_tokenizer.py. + This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should ref...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/kimi_k25/tokenizer.py
Write documentation strings for class attributes
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""This module provides some utilities for training""" import copy import logging @@ -41,6 +42,9 @@ class SmoothedValue: + """Track a series of values and provide access to smo...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/utils/misc.py
Auto-generate documentation strings for this file
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -67,6 +67,10 @@ return_tensors: Optional[Union[str, TensorType]] = None, data_format: ChannelDimension = ChannelDimension.FIRST, ): + """ + Checks validity of typically used arguments in an `ImageProcessorFast` `preprocess` method. + Raises `ValueError` if arguments incompatibility is caug...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/image_processing_utils_fast.py
Fully document this Python code with docstrings
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -43,6 +43,17 @@ output_split_sizes=None, input_split_sizes=None, ): + """ + All-to-all communication in the group. + + Args: + ctx (Any): Context object. + input (Tensor): Input tensor. + group (Group): The group object. + + R...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/dfnrope/modeling.py
Add docstrings to improve collaboration
# coding=utf-8 # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. # Copyright 2021 The HuggingFace Inc. 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.a...
--- +++ @@ -67,6 +67,9 @@ def to_numpy(obj): + """ + Convert a Paddle tensor, Numpy array, python list or python dict to a Numpy array. + """ if isinstance(obj, (dict, UserDict)): return {k: to_numpy(v) for k, v in obj.items()} elif isinstance(obj, (list, tuple)): @@ -125,6 +128,16 @@ ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/image_utils.py
Add missing documentation to my Python functions
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -38,6 +38,7 @@ def rotate_half(x: paddle.Tensor) -> paddle.Tensor: + """Rotates half the hidden dims of the input.""" x1 = x[..., : x.shape[-1] // 2] @@ -47,6 +48,15 @@ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1): + """ + Applies rotary positional em...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/llama/modeling.py
Please document this code using docstrings
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -62,6 +62,19 @@ class ModelProviderMixin(abc.ABC, Generic[ModelT]): + """A mixin that implements the ModelProvider pattern for PaddleFormers. + + The ModelProvider pattern solves ecosystem fragmentation by providing a standardized + way to instantiate models. This mixin provides a consistent `pr...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/model_provider.py
Add concise docstrings to each method
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. # Copyright 2026 The Moonshot AI 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 # # http:/...
--- +++ @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Encode structured tool declaration to typescript style string. +""" import dataclasses import json from collections.abc import Sequence @@ -25,18 +28,21 @@ class _SchemaRegist...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/kimi_k25/tool_declaration_ts.py
Annotate my code with docstrings
# Copyright (c) 2021 PaddlePaddle Authors. 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...
--- +++ @@ -50,6 +50,10 @@ def mha_ofa_forward(self, query, key, value, attn_mask=None, cache=None): + """ + monkey patch for MultiHeadAttention forward to accept head_mask + attn_mask[0] = attn_mask, attn_mask[1] = head_mask + """ key = query if key is None else key value = query if value is ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ofa_utils.py
Write docstrings describing functionality
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. 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 re...
--- +++ @@ -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. +""" +API for image and video processing, serving as a backend for PaddlePaddle processors. +""" from typing im...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/paddle_vision_utils.py
Add docstrings that explain logic
# Copyright 2025 the HuggingFace Team & PaddlePaddle Authors. 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 # # Unles...
--- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Image processor class for GLM-4.6V (PaddlePaddle version).""" import math from typing import Dict, List, Optional, Union @@ -41,12 +42,25 @@ def is_scaled_image(image: np.ndarr...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm_ocr/image_processor.py
Generate docstrings for script automation
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -23,6 +23,20 @@ startend_row_indices: paddle.Tensor, window_size: int = 5, ): + """ + Restrict start-end row indices to a sliding window range. + + Args: + startend_row_indices (`paddle.Tensor`, optional): + Tensor of shape (batch_size, num_heads, seq_length, bound_num) c...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/masking_utils.py
Please document this code using docstrings
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this fi...
--- +++ @@ -82,6 +82,12 @@ @dataclass(frozen=False, eq=True) class AddedToken: + """ + AddedToken represents a token to be added to a Tokenizer An AddedToken can have special options defining the + way it should behave. + The `normalized` will default to `not special` if it is not...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/legacy/tokenizer_utils_base.py
Generate docstrings with parameter types
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -55,12 +55,24 @@ class GPTModel(FleetGPTModel, PretrainedModel): + """ + GPTModel class that inherits from FleetGPTModel. + This class requires paddlefleet to be installed. + """ # GPTModel = FleetGPTModel def local_layer_spec(config: "GPTModelProvider") -> LayerSpec: + """Create...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/gpt_provider.py
Can you add docstrings to this Python file?
# coding=utf-8 # Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. # Copyright 2026 The Moonshot AI Inc. team and 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 obtai...
--- +++ @@ -13,6 +13,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. +"""Image processor class for Kimi-K2.5.""" import json import math @@ -186,6 +187,16 @@ medias: list[...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/kimi_k25/vision_processor.py
Insert docstrings into my code
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -23,6 +23,10 @@ def standardize_rope_params(config, rope_theta: float | dict[str, float] | None = None): + """ + Helper to standardize the config's rope params field by ensuring the params are defined for each + later type. For old model the fn will duplicate a single rope param in each layer ty...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/modeling_rope_utils.py
Write docstrings for algorithm functions
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -53,6 +53,7 @@ @dataclass class GLMMoEModelProvider(GPTModelProvider): + """Base provider for GLM MoE Models.""" moe_router_load_balancing_type: str = "seq_aux_loss" @@ -120,12 +121,14 @@ def rotate_half(x): + """Rotates half the hidden dims of the input.""" x1 = x[..., : x.shape[-...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm4_moe/modeling.py
Create docstrings for all classes and functions
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. # Copyright 2020 The HuggingFace 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 # # http://www....
--- +++ @@ -29,6 +29,12 @@ def tuple_output(outputs: Tuple[Tensor], loss: Optional[Tensor] = None): + """re-construct the outputs with one method which contains the simple logic + + Args: + outputs (Tuple[Tensor]): the source of the outputs + loss (Optional[Tensor], optional): the loss of the mo...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/model_outputs.py
Write docstrings for this repository
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2025 DeepSeek # # 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 t...
--- +++ @@ -43,6 +43,19 @@ num_out_tokens: Optional[int] = None, drop_and_pad: bool = False, ): + """Permute the tokens and probs based on the mask. + Tokens with the same designated expert will be grouped together. + The shape of mask is [tokens, num_experts], it indicates which experts were selecte...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/moe_utils.py
Add return value explanations in docstrings
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -52,6 +52,14 @@ chat_template: Optional[str] = None, **kwargs, ): + """ + PaddleFormers Glm46VProcessor fallback apply_chat_template. + + This method intentionally bypasses ProcessorMixin.apply_chat_template to avoid + processing_utils kwargs-grouping issues ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm_ocr/processor.py
Write docstrings for this repository
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. # Copyright (c) Microsoft Corporation. # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License")...
--- +++ @@ -29,6 +29,19 @@ def dispatching(x, dispatch_mask, scatter_index, num_experts, capacity): + """ + Rearranges the input tensor `x` based on gate results, truncates it according to the specified capacity, and performs padding. + + Args: + x (Tensor)[Seq, Dim]: The input tensor. + disp...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/moe_layer.py
Write reusable docstrings
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -51,6 +51,10 @@ def repeat_kv(hidden_states: paddle.Tensor, n_rep: int) -> paddle.Tensor: + """ + This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch, + num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_di...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm_ocr/modeling.py
Add standardized docstrings across the file
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -12,12 +12,55 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" GlmOCR model configuration.""" from ..configuration_utils import PretrainedConfig from ..modeling_rope_utils import rope_config_validation, standardize_rope_params class Gl...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm_ocr/configuration.py
Write clean docstrings for readability
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. # Copyright (c) Microsoft Corporation. # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License")...
--- +++ @@ -77,6 +77,16 @@ gates: paddle.Tensor, capacity_factor: float, ) -> paddle.Tensor: + """Calculate the capacity for each expert based on the gates and capacity factor. + + Args: + gates (paddle.Tensor): A tensor of shape [num_tokens, num_experts] representing the ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/moe_gate_auto.py
Add documentation for all methods
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -17,6 +17,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. +"""Qwen2_5_VL model configuration""" from ..configuration_utils import PretrainedConfig, layer_type_validation...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_5_vl/configuration.py
Create docstrings for each class method
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. # Copyright (c) Microsoft Corporation. # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License")...
--- +++ @@ -77,6 +77,16 @@ gates: paddle.Tensor, capacity_factor: float, ) -> paddle.Tensor: + """Calculate the capacity for each expert based on the gates and capacity factor. + + Args: + gates (paddle.Tensor): A tensor of shape [num_tokens, num_experts] representing the ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/moe_gate.py
Help me comply with documentation standards
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -17,6 +17,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. +"""Paddle Qwen2_5_VL model.""" from __future__ import annotations from dataclasses import dataclass @@ -112,1...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_5_vl/modeling.py
Generate docstrings for this script
# Copyright (c) 2020 PaddlePaddle Authors. 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...
--- +++ @@ -151,6 +151,16 @@ def prune_linear_layer(layer: nn.Linear, index: paddle.Tensor, dim: int = 0) -> nn.Linear: + """ + Prune a linear layer to keep only entries in index. + Used to remove heads. + Args: + layer (`paddle.nn.Linear`): The layer to prune. + index (`paddle.Tensor`): T...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/model_utils.py
Document helper functions with docstrings
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this fi...
--- +++ @@ -78,6 +78,13 @@ def convert_to_unicode(text): + """ + Converts `text` to Unicode (if it's not already), assuming utf-8 input. + Args: + text (str|bytes): Text to be converted to unicode. + Returns: + str: converted text. + """ if isinstance(text, str): return te...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/legacy/tokenizer_utils.py
Add docstrings to meet PEP guidelines
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The ZhipuAI Inc. team and 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 Lic...
--- +++ @@ -20,6 +20,45 @@ class RopeParameters(TypedDict, total=False): + """ + Args: + rope_theta (`float`): + The base period of the RoPE embeddings. + rope_type (`str`, *optional*, defaults to "default"): + The sub-variant of RoPE to use. Can be one of ['default', 'line...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm4v_moe/configuration.py
Create docstrings for all classes and functions
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. # Copyright (c) Microsoft Corporation. # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License")...
--- +++ @@ -29,6 +29,19 @@ def dispatching(x, dispatch_mask, scatter_index, num_experts, capacity): + """ + Rearranges the input tensor `x` based on gate results, truncates it according to the specified capacity, and performs padding. + + Args: + x (Tensor)[Seq, Dim]: The input tensor. + disp...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/moe_layer_auto.py
Add standardized docstrings across the file
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from i...
--- +++ @@ -18,6 +18,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. +"""processor class for Qwen2-VL.""" from typing import Optional, Union @@ -40,6 +41,20 @@ class Qwen2VLP...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_vl/processor.py
Generate docstrings with parameter types
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -17,6 +17,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. +"""Qwen3VL model configuration""" from ..configuration_utils import PretrainedConfig, layer_type_validation f...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_vl/configuration.py
Generate NumPy-style docstrings
# # Copyright 2024 Microsoft 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless ...
--- +++ @@ -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. +"""Paddle Phi3 model.""" from typing import Optional, Tuple, Union @@ -40,12 +41,14 @@ def rotate_half(x...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/phi3/modeling.py
Add docstrings that explain inputs and outputs
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original f...
--- +++ @@ -18,6 +18,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. +"""processor class for Qwen2.5-VL.""" from typing import Optional, Union @@ -40,6 +41,20 @@ class Qwen2_...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_5_vl/processor.py
Auto-generate documentation strings for this file
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from i...
--- +++ @@ -18,6 +18,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. +"""Fast image processor class for Qwen2-VL.""" from typing import Optional, Union import paddle @@ -45,6 +46,...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_vl/image_processor_fast.py
Add docstrings with type hints explained
# Copyright (c) 2024 PaddlePaddle Authors. 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...
--- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +This file is used for replacing Paddle's native Linear implementations with vendors' customized implementations +""" import paddle.distributed.fleet.meta_parallel as mpu from pad...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/linear_utils.py
Generate docstrings with examples
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team 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...
--- +++ @@ -13,6 +13,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. +"""processor class for Qwen3-VL.""" from typing import Optional, Union @@ -36,6 +37,20 @@ class Qwen3VLP...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_vl/processor.py
Create simple docstrings for beginners
# 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...
--- +++ @@ -26,6 +26,9 @@ def get_hcg(): + """ + get the hybrid comm group from fleet + """ return fleet.get_hybrid_communicate_group() @@ -63,9 +66,11 @@ class AllGatherVarlenOp(PyLayer): + """the shape of allgather can be not same for each rank""" @staticmethod def forward(ctx...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/sequence_parallel_utils.py
Help me write clear docstrings
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original f...
--- +++ @@ -17,6 +17,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. +"""Paddle Qwen3 model.""" from __future__ import annotations import json @@ -61,6 +62,7 @@ @dataclass clas...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3/modeling.py
Document this module using docstrings
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. # Copyright 2024 The Qwen team, Alibaba Group 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...
--- +++ @@ -12,6 +12,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. +"""Paddle Qwen2Moe model.""" from __future__ import annotations import copy @@ -55,6 +56,7 @@ @dataclass c...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_moe/modeling.py
Create Google-style docstrings for my code
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Image processor class for PaddleOCR-VL.""" import math from typing import Dict, List, Optional, Union @@ -41,6 +42,9 @@ def is_scaled_image(image: np.ndarray) -> bool: + """...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/paddleocr_vl/image_processor.py
Create documentation for each function signature
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original f...
--- +++ @@ -17,6 +17,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. +"""Paddle Qwen2 model.""" from __future__ import annotations import json @@ -61,6 +62,7 @@ @dataclass clas...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2/modeling.py
Write docstrings for this repository
# coding=utf-8 # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. # Copyright 2022 The HuggingFace Inc. 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.a...
--- +++ @@ -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. +""" + Processing saving/loading class for common processors. +""" import bisect import copy @@ -63,6 +66,10 @...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/processing_utils.py
Generate docstrings with examples
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -17,6 +17,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. +"""Qwen3VLMoemodel configuration""" from ..configuration_utils import PretrainedConfig, layer_type_validation ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_vl_moe/configuration.py
Add docstrings for production code
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -17,6 +17,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. +"""Paddle Qwen3_VL_Moe model.""" from __future__ import annotations import types @@ -186,12 +187,14 @@ de...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_vl_moe/modeling.py
Create docstrings for all classes and functions
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this fi...
--- +++ @@ -69,6 +69,10 @@ class TensorType(ExplicitEnum): + """ + Possible values for the `return_tensors` argument in [`PreTrainedTokenizerBase.__call__`]. Useful for + tab-completion in an IDE. + """ PADDLE = "pd" NUMPY = "np" @@ -80,6 +84,21 @@ self._wrap_return_tensor_methods() ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/tokenizer_utils.py
Add well-formatted docstrings
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -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. +"""Paddle Qwen3-Next model.""" from typing import Any, List, Optional @@ -74,6 +75,18 @@ class Qwen3Next...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_next/modeling.py
Provide docstrings following PEP 257
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2025 DeepSeek # # 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 t...
--- +++ @@ -25,33 +25,69 @@ class _DispatchManager(ABC): + """ + A manager class to handle dispatch and combine processes for MoE models. + + DispatcherManager handles token dispatching according to the routing_map of format + [num_local_tokens, world_size, num_instances]. The routing_map is a 3D tensor...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/token_dispatcher.py
Add docstrings to existing functions
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2024 The Qwen team, Alibaba Group. 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...
--- +++ @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # This code is adapted from https://github.com/QwenLM/Qwen3-VL/blob/main/qwen-vl-utils/src/qwen_vl_utils/vision_process.py +"""Processing functions for image and video inputs for Qwen2/2.5-...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_vl/vision_process.py
Add docstrings to my Python code
# Copyright 2024 Microsoft 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless re...
--- +++ @@ -12,11 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" Phi-3 model configuration.""" from ..configuration_utils import PretrainedConfig, layer_type_validation from ..modeling_rope_utils import rope_config_validation, standardize_rope_...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/phi3/configuration.py
Add docstrings explaining edge cases
# Copyright (c) 2022 PaddlePaddle Authors. 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 app...
--- +++ @@ -12,6 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +This code is based on https://github.com/pytorch/pytorch/blob/master/torch/nn/init.py +This copyright of pytorch/pytorch is a BSD-style license, as found in the LICENSE file. +""" ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/initializer.py
Provide clean and structured docstrings
# 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...
--- +++ @@ -34,6 +34,20 @@ tensor_parallel_output=True, training=True, ): + """ + Parallel matmul + Args: + lm_output: x for matmul + logit_weights: y for matmul + bias (Tensor, optional): Bias tensor. Default is None. + transpose_y (bool, optional): Whether to transpose y...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/tensor_parallel_utils.py
Generate docstrings for script automation
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -38,6 +38,17 @@ class PaddleOCRVLProcessor(ProcessorMixin): + r""" + [`PaddleOCRVLProcessor`] offers all the functionalities of [`PaddleOCRImageProcessor`] and [`Ernie4_5Tokenizer`]. See the + [`~PaddleOCRVLProcessor.__call__`] and [`~PaddleOCRVLProcessor.decode`] for more information. + Args...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/paddleocr_vl/processor.py
Document this code for team use
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -77,6 +77,7 @@ def get_layer_spec(is_vit, normalization) -> LayerSpec: + """Transformer Layer Spec.""" attn_mask_type = AttnMaskType.no_mask if is_vit else AttnMaskType.causal if normalization == "LayerNorm": norm = LayerNorm @@ -128,11 +129,18 @@ class Qwen3VLTextTransformerLay...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_vl/modeling_fleet.py
Generate documentation strings for clarity
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from i...
--- +++ @@ -18,6 +18,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. +"""video processor class for Qwen2-VL.""" import math from typing import Optional, Union @@ -97,6 +98,29 @@ ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen2_vl/video_processor.py
Help me write clear docstrings
# Copyright (c) 2020 PaddlePaddle Authors. 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...
--- +++ @@ -63,6 +63,15 @@ def convert_ndarray_dtype(np_array: np.ndarray, target_dtype: str) -> np.ndarray: + """convert ndarray + + Args: + np_array (np.ndarray): numpy ndarray instance + target_dtype (str): the target dtype + + Returns: + np.ndarray: converted numpy ndarray instance...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/utils.py
Add detailed docstrings explaining each function
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen team, Alibaba Group 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...
--- +++ @@ -12,6 +12,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. +"""Paddle Qwen3Moe model.""" from __future__ import annotations import copy @@ -55,6 +56,7 @@ @dataclass c...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_moe/modeling.py
Fully document this Python code with docstrings
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommo...
--- +++ @@ -17,6 +17,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. +"""Paddle Qwen3_VL model.""" from __future__ import annotations from dataclasses import dataclass @@ -166,12 ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/qwen3_vl/modeling.py
Add docstrings including usage examples
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. 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 re...
--- +++ @@ -80,6 +80,7 @@ @property def timestamps(self) -> list[float]: + "Timestamps of the sampled frames in seconds." if self.fps is None or self.frames_indices is None: raise ValueError("Cannot infer video `timestamps` when `fps` or `frames_indices` is None.") retur...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/video_utils.py
Help me document legacy Python code
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -13,6 +13,7 @@ # limitations under the License. +"""Paddle PaddleOCR-VL model.""" from contextvars import ContextVar from dataclasses import dataclass @@ -58,6 +59,7 @@ def rotate_half(x): + """Rotates half the hidden dims of the input.""" x1 = x[..., : x.shape[-1] // 2] x2 = x[..., ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/paddleocr_vl/modeling.py
Write reusable docstrings
# Copyright (c) 2024 PaddlePaddle Authors. 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...
--- +++ @@ -71,17 +71,20 @@ def set_recompute_id(value=-1): + """switch recompute id to the given value""" global _recompute_id _recompute_id = str(value) def get_recompute_id(): + """get current recompute id""" global _recompute_id return str(_recompute_id) @contextlib.contextma...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/refined_recompute.py
Add docstrings that explain logic
# coding=utf-8 # Copyright (c) 2025 PaddlePaddle Authors. 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 re...
--- +++ @@ -189,6 +189,9 @@ self, video: "paddle.Tensor", ) -> VideoInput: + """ + Converts a video to RGB format. + """ video = grayscale_to_rgb(video) if video.shape[-3] == 3 or not (video[..., 3, :, :] < 255).any(): return video @@ -204,6 +207...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/video_processing_utils.py
Add docstrings to improve readability
# coding:utf-8 # Copyright (c) 2020 PaddlePaddle Authors. 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 req...
--- +++ @@ -40,6 +40,12 @@ class Logger(object): + """ + Default logger in PaddleFormers + + Args: + name(str) : Logger name, default is 'PaddleFormers' + """ def __init__(self, name: str = None): name = "PaddleFormers" if not name else name @@ -93,6 +99,13 @@ @contextlib.co...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/log.py
Generate consistent documentation across files
# Copyright (c) 2022 PaddlePaddle Authors. 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...
--- +++ @@ -48,11 +48,20 @@ class SerializationError(Exception): + """Exception for serialization""" pass def seek_by_string(file_handler: BufferedReader, string: str, file_size: int) -> int: + """seek the index of file-handler with target words + Args: + file_handler (BufferedReader): f...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/serialization.py
Provide docstrings following PEP 257
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -365,6 +365,15 @@ axis: int, DEQUANT_SCALE_ROUNDING_MODE: DequantScaleRoundingMode = DequantScaleRoundingMode.ROUND_UP, ): + """ + Convert the src weights to mx format. The src weight is quantized along the axis dimension. + + If weight_quant_type is paddle.uint8, we output mxfp4 where two...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/upcast_downcast_triton.py
Expand my code with proper documentation strings
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve. # # 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 applic...
--- +++ @@ -26,6 +26,26 @@ class ProfilerOptions(object): + """ + Use a string to initialize a ProfilerOptions. + The string should be in the format: "key1=value1;key2=value;key3=value3". + For example: + "profile_path=model.profile" + "batch_range=[50, 60]; profile_path=model.profile" + ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/profiler.py
Fully document this Python code with docstrings
# Copyright (c) 2024 PaddlePaddle Authors. 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...
--- +++ @@ -74,6 +74,10 @@ def _cache_commit_hash_for_specific_revision(storage_folder: str, revision: str, commit_hash: str) -> None: + """Cache reference between a revision (tag, branch or truncated commit hash) and the corresponding commit hash. + + Does nothing if `revision` is already a proper `commit_ha...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/download/common.py
Write docstrings for data processing functions
# Copyright (c) 2022 PaddlePaddle Authors. 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...
--- +++ @@ -37,6 +37,18 @@ def static_params_to_dygraph(model, static_tensor_dict): + """Simple tool for convert static parameters to dygraph parameters dict. + + **NOTE** The model must both support static graph and dygraph mode. + + Args: + model (nn.Layer): the model of a neural network. + ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/tools.py
Add return value explanations in docstrings
# Copyright (c) 2024 PaddlePaddle Authors. 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...
--- +++ @@ -38,6 +38,7 @@ class PDCErrorCode(Enum): + """Error Code For PDCTools usage""" # success Success = 0 @@ -61,14 +62,27 @@ class PDCTools: + """PDCTools""" def __init__(self): + """ """ self._pdc_agent_bin = PDC_AGENT_BIN self._hash_sum_bin = HASH_SUM_B...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/pdc_sdk.py
Write clean docstrings for readability
# Copyright (c) 2022 PaddlePaddle Authors. 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...
--- +++ @@ -22,6 +22,9 @@ class _LazyModule(ModuleType): + """ + Module class that surfaces all objects but only performs associated imports when the objects are requested. + """ # Very heavily inspired by optuna.integration._IntegrationModule # https://github.com/optuna/optuna/blob/master/optu...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/lazy_import.py
Add docstrings for better understanding
# Copyright (c) 2023 PaddlePaddle Authors. 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...
--- +++ @@ -25,6 +25,16 @@ def convert_file_size_to_int(size: Union[int, str]): + """ + Converts a size expressed as a string with digits an unit (like `"5MB"`) to an integer (in bytes). + Args: + size (`int` or `str`): The size to convert. Will be directly returned if an `int`. + Example: + `...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/distributed.py
Document my Python code with docstrings
# Copyright (c) 2025, Tri Dao. # Ported from Flash Attention: https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/ops/triton/rotary.py # Original code licensed under BSD-3-Clause license. # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (t...
--- +++ @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Triton Rotary Position Embedding for PaddlePaddle.""" import paddle @@ -64,6 +65,22 @@ BLOCK_H: tl.constexpr, BLOCK_M: tl.constexpr, ): + """ + Triton kernel for r...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/triton_kernels/rope_triton.py
Add docstrings to improve readability
# Copyright (c) 2020 PaddlePaddle Authors. 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 app...
--- +++ @@ -20,6 +20,60 @@ class DistributedBatchSampler(paddle.io.BatchSampler): + """Sampler that restricts data loading to a subset of the dataset. + + In such case, each process can pass a DistributedBatchSampler instance + as a DataLoader sampler, and load a subset of the original dataset that + is...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/batch_sampler.py
Add docstrings explaining edge cases
# Copyright (c) 2020 PaddlePaddle Authors. 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 applic...
--- +++ @@ -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. +""" +This module is used to store environmental variables in PaddleFormers. +PF_HOME --> the root ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/env.py
Auto-generate documentation strings for this file
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -32,6 +32,20 @@ tensor_model_parallel_size: int, logging_enabled: bool = True, ) -> int: + """Calculate padded vocab size for tensor parallelism. + + This function pads the vocabulary size to ensure it's divisible by the required + multiple for efficient tensor parallel operations. + + ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/vocab_utils.py
Add detailed documentation for each class
# Copyright (c) 2025 PaddlePaddle Authors. 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...
--- +++ @@ -26,6 +26,34 @@ dtype: Optional[paddle.dtype] = paddle.bfloat16, is_causal: Optional[bool] = None, ): + """ + Recover 4-D attention_mask from attn_mask_startend_row_indices. + + Args: + attn_mask_startend_row_indices (paddle.Tensor): + A column-wise sparse attention mask ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/masking_utils.py
Write proper docstrings for these functions
# Copyright (c) 2024 PaddlePaddle Authors. 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...
--- +++ @@ -89,9 +89,14 @@ class LocalTokenNotFoundError(EnvironmentError): + """Raised if local token is required but not found.""" def _clean_token(token: Optional[str]) -> Optional[str]: + """Clean token by removing trailing and leading spaces and newlines. + + If token is an empty string, return N...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/download/aistudio_hub_download.py
Generate docstrings for script automation
# Copyright (c) 2020 PaddlePaddle Authors. 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...
--- +++ @@ -82,10 +82,29 @@ def is_url(path): + """ + Whether path is URL. + Args: + path (string): URL string or not. + """ return path.startswith("http://") or path.startswith("https://") def get_weights_path_from_url(url, md5sum=None): + """Get weights path from WEIGHT_HOME, if no...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/downloader.py
Can you add docstrings to this Python file?
# Copyright (c) 2020 PaddlePaddle Authors. 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...
--- +++ @@ -30,10 +30,12 @@ def is_git_repo(dir: str) -> bool: + """Is the given directory version-controlled with git?""" return os.path.exists(os.path.join(dir, ".git")) def have_git() -> bool: + """Can we run the git executable?""" try: subprocess.check_output(["git", "--help"]) ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/setup.py
Create documentation strings for testing functions
# Copyright (c) 2023 PaddlePaddle Authors. 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...
--- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Git utilities.""" # https://github.com/python/mypy/blob/2c2d126cc742f2467045d36780c33bb8fb77a614/mypy/git.py#L1-L34 # Used also from setup.py, so don't pull in anything additional he...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/version/git.py
Generate missing documentation strings
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -18,6 +18,18 @@ def parse_loss_values(log_content): + """Parse loss values from training log + + The log format can be either: + - loss: 7.11594725 learning_rate: 5e-07 global_step: 1 ... + - loss: 12.24401569, learning_rate: 2.5e-06, global_step: 5, ... + + Args: + log_content (str...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/scripts/ci_utils/log_analyzer.py
Document functions with detailed explanations
# Copyright (c) 2022 PaddlePaddle Authors. 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...
--- +++ @@ -31,6 +31,13 @@ self._id = name + "_" + str(uuid.uuid4())[-6:] def __call__(self, sample, context=None): + """Process a sample. + Args: + sample (dict): a dict of sample, eg: {'image':xx, 'label': xxx} + context (dict): info about this sample processing + ...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/image_utils.py
Add professional docstrings to my codebase
# Copyright (c) 2022 PaddlePaddle Authors. 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 applic...
--- +++ @@ -229,6 +229,10 @@ def is_paddle_available() -> bool: + """check if `torch` package is installed + Returns: + bool: if `torch` is available + """ return is_package_available("paddle") @@ -241,35 +245,70 @@ def is_torch_available() -> bool: + """check if `torch` package is i...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/utils/import_utils.py
Generate descriptive docstrings automatically
# Copyright (c) 2026 PaddlePaddle Authors. 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...
--- +++ @@ -19,17 +19,36 @@ class TrainingTestRunner: + """Helper class for training tests - handles log parsing and validation only.""" def __init__(self, baseline_path, tolerance=1e-6): + """ + Initialize the test runner. + + Args: + baseline_path: Path to the baseline lo...
https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/scripts/ci_utils/training_utils.py
Annotate my code with docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -59,6 +59,38 @@ class LLMEngine(LLMEngine): + """An LLM engine that receives requests and generates texts. + + This is the main class for the vLLM engine. It receives requests + from clients and generates texts from the LLM. It includes a tokenizer, a + language model (possibly distributed ac...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_6_3/llm_engine_sp.py
Create docstrings for each class method
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -23,6 +23,7 @@ class TokenizerGroup: + """A group of tokenizers that can be used for LoRA adapters.""" def __init__(self, tokenizer: PreTrainedTokenizer, enable_lora: bool, max_num_seqs: int, max_input_length: Optional[int]): @@ -32,9 +33,11 @@ self.lora_tokenizers = L...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_5_4/tokenizer.py
Add docstrings to existing functions
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -29,6 +29,48 @@ class ModelConfig: + """Configuration for the model. + + Args: + model: Name or path of the huggingface model to use. + tokenizer: Name or path of the huggingface tokenizer to use. + tokenizer_mode: Tokenizer mode. "auto" will use the fast tokenizer if + ...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_3_1/config.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,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 class of WorkerGroup +""" import logging import threading import signal @@ -55,6 +58,10 @@ class ...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/single_controller/base/worker_group.py
Include argument descriptions in docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. # # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX # and OPT implementations in this library. It has been modified from its # original forms to accommodate minor ar...
--- +++ @@ -17,6 +17,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. +"""PyTorch LLaMA model with Megatron-style acceleration.""" from typing import Optional, Tuple, Union @@ -42...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/models/llama/megatron/modeling_llama_megatron.py
Document this module using docstrings
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # Adapted from https://github.com/vllm-project/vllm/blob/main/vllm/worker/worker.py +"""A GPU worker class.""" import os import gc from typing import Dict, List, Tuple, Optional, Union @...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_4_2/worker.py
Help me document legacy Python code
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -25,6 +25,7 @@ @dataclass class EngineArgs: + """Arguments for vLLM engine.""" model_hf_config: PretrainedConfig = None dtype: str = 'auto' kv_cache_dtype: str = 'auto' @@ -58,6 +59,7 @@ @staticmethod def add_cli_args(parser: argparse.ArgumentParser) -> argparse.ArgumentParser...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_3_1/arg_utils.py
Write docstrings for this repository
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -62,6 +62,7 @@ def get_model_loader(load_config: LoadConfig) -> BaseModelLoader: + """Get a model loader based on the load format.""" if isinstance(load_config.load_format, type): return load_config.load_format(load_config) @@ -100,6 +101,7 @@ class DummyModelLoader(BaseModelLoader...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_5_4/model_loader.py
Write docstrings including parameters and return values
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -33,6 +33,58 @@ class LLM: + """An LLM for generating texts from given prompts and sampling parameters. + + This class includes a tokenizer, a language model (possibly distributed + across multiple GPUs), and GPU memory space allocated for intermediate + states (aka KV cache). Given a batch o...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_4_2/llm.py
Insert docstrings into my code
# Copyright 2024 Bytedance Ltd. and/or its affiliates # Copyright 2023 The vLLM 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 # # Unle...
--- +++ @@ -40,6 +40,7 @@ class SPMDGPUExecutor(ExecutorBase): + """SPMD-based multi-GPU executor implementations.""" def __init__( self, @@ -111,6 +112,15 @@ self.worker.load_model() def determine_num_available_blocks(self) -> Tuple[int, int]: + """Determine the number of a...
https://raw.githubusercontent.com/Jiayi-Pan/TinyZero/HEAD/verl/third_party/vllm/vllm_v_0_6_3/spmd_gpu_executor.py