instruction stringclasses 100
values | code stringlengths 78 193k | response stringlengths 259 170k | file stringlengths 59 203 |
|---|---|---|---|
Add docstrings for production 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... | --- +++ @@ -24,6 +24,7 @@
def _get_fa_version():
+ """Get the FlashAttention version based on environment flags."""
if paddle.get_flags(["FLAGS_cudnn_deterministic"])["FLAGS_cudnn_deterministic"]:
return 2
return paddle.base.framework.get_flags(["FLAGS_flash_attn_version"])["FLAGS_flash_attn_v... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/attention/sink_impl.py |
Create documentation strings for testing functions | # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 The Google AI Language Team Authors and 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 Licens... | --- +++ @@ -64,6 +64,10 @@
def _make_sliding_window_mask(input_shape, past_key_values_length=0, window_size=5):
+ """
+ Generate a sliding window mask that restricts each position to only attend to historical positions within the window.
+ Format: [bsz, 1, tgt_seq_len, src_seq_len], where True indicates al... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/generation/utils.py |
Add detailed documentation for each class | # 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... | --- +++ @@ -24,6 +24,10 @@
class LogitsProcessor(ABC):
+ """
+ Abstract base class for all logit processors that can be applied during
+ generation.
+ """
def __call__(self, input_ids: paddle.Tensor, logits: paddle.Tensor):
raise NotImplementedError(
@@ -32,6 +36,7 @@
class LogitsPro... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/generation/logits_process.py |
Add docstrings to meet PEP guidelines | # 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... | --- +++ @@ -24,15 +24,45 @@
class BaseStreamer:
+ """
+ Base class from which `.generate()` streamers should inherit.
+ """
def put(self, value):
+ """Function that is called by `.generate()` to push new tokens"""
raise NotImplementedError()
def end(self):
+ """Function... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/generation/streamers.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... | --- +++ @@ -21,9 +21,23 @@
class AlltoAll(PyLayer):
+ """
+ Custom PyLayer for All-to-All communication with backward pass.
+ """
@staticmethod
def forward(ctx, x, group, sync_op=True):
+ """
+ Perform All-to-All communication in the group.
+
+ Args:
+ x: Input t... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/all_to_all.py |
Help me add docstrings to my project | # 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... | --- +++ @@ -24,6 +24,17 @@
def allgather_async(input, group=None):
+ """Perform asynchronous All-Gather operation for model parallelism.
+
+ Args:
+ input (Tensor): Local tensor to gather (shape: [N, ...])
+ group (ProcessGroup): Model parallel group (default: auto-detected)
+
+ Return... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/all_gather.py |
Add docstrings for production code | # 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... | --- +++ @@ -23,6 +23,9 @@
@dataclass
class MergeConfig:
+ """
+ This is the configuration class to store the configuration of a [`MergeKit`].
+ """
# Common parameters
tensor_type: str = field(
@@ -129,6 +132,12 @@ return self.__dict__
def save_pretrained(self, save_directory):
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/mergekit/merge_config.py |
Document functions with detailed explanations | # 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,9 @@ # limitations under the License.
+"""
+moe_layer_all_gather
+"""
import inspect
from typing import List, Optional, Tuple
@@ -47,9 +50,25 @@
class ReshardCombineWeight(PyLayer):
+ """
+ Perform weights transform.
+ """
@staticmethod
def forward(ctx, input, group... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/moe_allgather_layer.py |
Fill in missing docstrings in my code | # 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... | --- +++ @@ -22,12 +22,27 @@
class StoppingCriteria(ABC):
+ """
+ Abstract base class for all stopping criteria that can be applied during
+ generation.
+ """
def __call__(self, input_ids: paddle.Tensor, logits: paddle.Tensor, **kwargs):
raise NotImplementedError(f"{self.__class__} is an ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/generation/stopping_criteria.py |
Generate docstrings for each module | # 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... | --- +++ @@ -81,6 +81,9 @@
class RLHFDataset(Dataset):
+ """
+ We assume the dataset contains a column that contains prompts and other information
+ """
data: list[dict[str, paddle.Tensor]]
_SENTINEL: Any = object()
@@ -135,6 +138,7 @@ truncation: bool = True,
max_length: int | ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/datasets/rlhf_datasets/rl_dataset.py |
Generate consistent documentation across files | # 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,16 @@
def calc_padding_size(seq_len: int, training_args) -> int:
+ """
+ Calculate appropriate padding size based on training parameters
+
+ Args:
+ seq_len (int): Sequence length
+ training_args: Training parameter object
+
+ Returns:
+ int: Aligned sequence le... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/datasets/collate.py |
Include argument descriptions 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... | --- +++ @@ -34,6 +34,9 @@ raise NotImplementedError(f"{self.merge_config.merge_type} is not supported yet.")
def linear(self, tensor_list):
+ """
+ Linear interpolation between multiple values.
+ """
# init weight
weight_list = self.merge_config.weight_list
... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/mergekit/merge_method.py |
Generate descriptive docstrings automatically | # 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.
+"""Useful data utility."""
import json
import time
@@ -29,10 +30,12 @@
def round_up_to_multiple_of_8(n):
+ """round up to multiple of 8"""
return (n + 7) & ~7
def pri... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/datasets/data_utils.py |
Generate docstrings for this script | # 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... | --- +++ @@ -90,6 +90,13 @@
class QuantizationLoRALinear(QuantizationLoRABaseLinear):
+ """
+ Quantization lora Linear layer.
+ The code implementation refers to paddlenformers.peft.lora.lora_layers.LoRALinear.
+ https://github.com/PaddlePaddle/PaddleFormers/blob/develop/paddleformers/peft/lora/lora_laye... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/peft/lora/lora_quantization_layers.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... | --- +++ @@ -34,14 +34,32 @@
class LoRAGATrainer(Trainer):
+ """A Trainer class for Lora-GA gradient estimation."""
def __init__(self, loraga_init_iters: int, gradient_offload: bool, **kwargs):
+ """
+ Initialize the Trainer class for Lora-GA gradient estimation.
+
+ Args:
+ lor... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/peft/lora/loraga_utils.py |
Add docstrings including usage examples | # 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... | --- +++ @@ -59,6 +59,10 @@
class AddAuxiliaryLoss(paddle.autograd.PyLayer):
+ """
+ The trick function of adding auxiliary (aux) loss,
+ which includes the gradient of the aux loss during backpropagation.
+ """
@staticmethod
def forward(ctx, x, loss):
@@ -156,6 +160,7 @@ gate_logits:... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe_deepep/moe_loss.py |
Add docstrings to improve code quality | # 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,29 @@
def parse_args(args, mtp_enable=False, is_embed=False):
+ """
+ Parses input arguments and converts them into model-ready format.
+ Processes different input argument patterns into standardized hidden states,
+ attention masks and position IDs tensors. All output tensors will ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/pp_model.py |
Provide clean and structured 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... | --- +++ @@ -23,6 +23,25 @@ def calc_lm_head_logits(
config, hidden_states, weight, bias, tensor_parallel_output=None, training=True, gather_hidden_states=False
):
+ """
+ Calculate language model head logits with support for various parallelization strategies.
+
+ This is the core function that computes ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/criterion/loss_utils.py |
Document functions with detailed explanations | # 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... | --- +++ @@ -260,6 +260,7 @@
class QuantizationLinear(nn.Layer):
+ """Quantization Linear layer."""
def __init__(
self,
@@ -419,6 +420,14 @@
class ColumnParallelQuantizationLinear(nn.Layer):
+ """Quantization Linear layer with mp parallelized(column).
+ The code implementation refers to ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/quantization/quantization_linear.py |
Add docstrings to my Python code | # Copyright 2020 The HuggingFace Team. All rights reserved.
# 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.... | --- +++ @@ -81,6 +81,12 @@
class VisualDLCallback(TrainerCallback):
+ """
+ A [`TrainerCallback`] that sends the logs to [VisualDL](https://www.paddlepaddle.org.cn/paddle/visualdl).
+ Args:
+ vdl_writer (`LogWriter`, *optional*):
+ The writer to use. Will instantiate one if not set.
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/integrations.py |
Create docstrings for API 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... | --- +++ @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""_summary_
+
+Returns:
+ _type_: _description_
+"""
import inspect
import itertools
@@ -35,9 +40,23 @@
class GateCombine(PyLayer):
+ """
+ Custom PyLayer for gate comb... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/moe_alltoall_layer.py |
Add docstrings including usage examples | # 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... | --- +++ @@ -35,6 +35,16 @@
def dequant_unified_optimizer(state_dict, ckpt_quant_stage, scale_dict, use_pd=False):
+ """
+ dequantize unified optimizer state dict.
+ Args:
+ state_dict (`dict`):
+ unified checkpoint optimizer state dict.
+ ckpt_quant_stage (`str`):
+ chec... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/quantization/unified_checkpoint_quantization.py |
Create docstrings for all classes and 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... | --- +++ @@ -18,6 +18,16 @@
def cal_ratio(m, v, eps=1e-8):
+ """
+ cal part adam update ratio.
+ Args:
+ m (`paddle.Tensor`):
+ moment in Adam optimizer.
+ v (`paddle.Tensor`):
+ variance in Adam optimizer.
+ eps (`int`):
+ epsilon in Adam optimizer.
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/quantization/checkpoint_quantization_utils.py |
Help me document legacy Python code | # 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... | --- +++ @@ -27,6 +27,23 @@
@dataclass
class QuantizationConfig:
+ """
+ This is the configuration class to store quantization configuration.
+ Args:
+ weight_quantize_algo: Weight quantization algorithm.
+ quant_type: Quantization type applied to weight and activation, weight may still keep in... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/quantization/quantization_config.py |
Document this module 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... | --- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Common distributed utils.
+"""
from typing import Any, Callable, List, Union
@@ -27,10 +30,25 @@
def get_hcg():
+ """
+ Get hybrid communicate group.
+ """
ret... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/utils.py |
Write docstrings for utility 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... | --- +++ @@ -13,6 +13,9 @@ # limitations under the License.
+"""
+moe_layer_all_gather
+"""
from typing import List, Optional
@@ -82,8 +85,19 @@
class MoEStatics(nn.Layer):
+ """
+ Stores MoE (Mixture of Experts) statistics
+ and expert usage information.
+ """
def __init__(self, config, ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/moe_block.py |
Help me write clear 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... | --- +++ @@ -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.
+"""Save and load single card checkpoint for Unified Checkpoint"""
import gc
import json
@@ -64,6 +65,7 @@
... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/load_save_single_card.py |
Document functions with detailed explanations | # 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... | --- +++ @@ -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.
+"""Unfied checkpoint locally loading functions."""
import gc
import json
@@ -52,6 +53,9 @@ def load_unified_c... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/load_local.py |
Write docstrings that follow conventions | # 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://ww... | --- +++ @@ -65,10 +65,24 @@
class PdArgumentParser(ArgumentParser):
+ """
+ This subclass of `argparse.ArgumentParser` uses type hints on dataclasses to generate arguments.
+
+ The class is designed to play well with the native argparse. In particular, you can add more (non-dataclass backed)
+ arguments... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/argparser.py |
Add return value explanations in 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... | --- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+top2gate
+"""
from functools import partial
from typing import Tuple
@@ -35,12 +38,37 @@
def masked_fill(x, mask, value):
+ """
+ Fills elements of the input tensor wit... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe/topk_gate.py |
Generate docstrings with parameter types | # 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... | --- +++ @@ -1089,6 +1089,7 @@ return self.model
def __getattr__(self, name: str):
+ """Forward missing attributes to the wrapped module."""
try:
return super().__getattr__(name) # defer to nn.Layer's logic
except AttributeError:
@@ -1118,6 +1119,17 @@ merge_... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/peft/lora/lora_model.py |
Fill in missing docstrings in 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... | --- +++ @@ -190,6 +190,14 @@
def _init_expert_parallel(self):
def _parse_moe_expert_parallel(num_experts: int, expert_model_parallel_size: int) -> int:
+ """
+ Args:
+ num_experts: Total number of experts
+ expert_model_parallel_size: Expert parallel gr... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe_deepep/modular_moe_layer.py |
Improve my code by adding docstrings | # 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... | --- +++ @@ -182,6 +182,9 @@ self._lr_scheduler = lr_scheduler
def map_names(self, map_func):
+ """
+ rename param names and change the keys of the dicts(model_weights, opt, master_weights) accordingly
+ """
def map_key(state_dict, map_key_func):
state_dict... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/utils/reshard/common.py |
Add clean documentation to messy code | # Copyright 2020-present the HuggingFace Inc. team.
# 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.o... | --- +++ @@ -22,6 +22,7 @@
class _Timer:
+ """Profile Timer for recording time taken by forward/ backward/ reduce/ step."""
def __init__(self, name):
self.name = name
@@ -30,6 +31,7 @@ self.start_time = time.time()
def start(self):
+ """Start the timer."""
assert not... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/plugins/timer.py |
Write reusable docstrings | # 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... | --- +++ @@ -24,6 +24,17 @@
@dataclass
class LoRAConfig:
+ """
+ This is the configuration class to store the configuration of a [`LoRAModel`].
+ Args:
+ r (`int`): Lora attention dimension
+ target_modules (`Union[List[str],str]`): The names of the modules to apply Lora to.
+ trainable_... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/peft/lora/lora_config.py |
Write Python docstrings for this snippet | # 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... | --- +++ @@ -524,6 +524,29 @@ return model
def merge_auto_dist_configs(self, configs):
+ """
+ Merged all auto dist configs into one config.
+ configs is a list of config,every config is a dict,which means a model auto_dist_config.
+ [
+ {
+ mp_config ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/peft/lora/auto_lora_model.py |
Add docstrings to improve collaboration | # 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... | --- +++ @@ -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.
+"""Shared Memory Utils"""
from dataclasses import dataclass
from typing import List, Mapping, Tuple
@@ -46,6 ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/shared_memory_utils.py |
Improve documentation using 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... | --- +++ @@ -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.
+"""Unified Checkpoint Utility Functions"""
import copy
import os
@@ -67,6 +68,13 @@
class UnifiedCheckpoi... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/utils.py |
Add docstrings for production 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... | --- +++ @@ -42,10 +42,35 @@ topk: int,
token_dispatcher,
) -> Tuple[paddle.Tensor, paddle.Tensor, paddle.Tensor]:
+ """
+ Args:
+ hidden_states: Input hidden states, shape: [batch_size*seq_len, hidden_size] or [batch_size, seq_len, hidden_size]
+ topk_indices: I... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/nn/moe_deepep/moe_communication.py |
Add missing documentation to my Python functions | # Copyright 2020-present the HuggingFace Inc. team.
# 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.o... | --- +++ @@ -61,6 +61,7 @@
def paddle_pad_and_concatenate(tensor1, tensor2, padding_index=-100):
+ """Concatenates `tensor1` and `tensor2` on first axis, applying padding on the second if necessary."""
if len(tensor1.shape) == 1 or tensor1.shape[1] == tensor2.shape[1]:
return paddle.cat((tensor1, te... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/utils/helper.py |
Auto-generate documentation strings for this file | # 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... | --- +++ @@ -114,6 +114,16 @@ self.print_checkpoint_file_info(flags)
def load_from_hybrid_parallel_checkpoint(self):
+ """
+ Automatically and inplace load the distributed checkpoint stored in hybrid parallel mode into the auto parallel state_dict.
+ The main logic is as follows:
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/utils/ckpt_converter.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... | --- +++ @@ -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.
+"""Support Sharding Stage1 V2(split param) for Unified Checkpoint"""
import gc
import os
@@ -54,6 +55,7 @@ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/sharding_split_param_utils.py |
Create docstrings for each class method | # 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... | --- +++ @@ -95,6 +95,16 @@ self.async_handler = AsyncCheckpointHandler(args)
def save_unified_checkpoint(self, model, optimizer, output_dir, signal_dir=None, save_to_hf=False):
+ """save unified checkpoint
+
+ Args:
+ model (PretrainedModel): model to save
+ output_dir... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/unified_checkpoint.py |
Add docstrings to improve collaboration | # 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... | --- +++ @@ -20,6 +20,14 @@
class QuantedLoRALinear(ConvertibleQuantedLayer):
+ """
+ The computational logic of QuantizedLoRALinear is the same as LoRALinear.
+ The only difference is that its inputs are all fake quantized.
+
+ Note:
+ In order for proper quantization of this layer, we do (W + AB... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/peft/lora/lora_quant_layers.py |
Generate documentation strings for clarity | # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 Google AI, Google Brain and 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
#
# ... | --- +++ @@ -62,6 +62,67 @@ subfolder: str = "",
**kwargs,
):
+ """
+ Loads the tokenizer configuration from a pretrained model tokenizer configuration.
+
+ Args:
+ pretrained_model_name_or_path (`str` or `os.PathLike`):
+ This can be either:
+
+ - a string, the *model id*... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/auto/tokenizer.py |
Generate helpful docstrings for debugging | # 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/nn/moe_deepep/moe_gate.py |
Generate docstrings with parameter types | # coding=utf-8
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this fi... | --- +++ @@ -24,6 +24,7 @@
class CacheLayerMixin(ABC):
+ """Base, abstract class for a single layer's cache."""
is_compileable = False
@@ -58,16 +59,19 @@ ...
def offload(self):
+ """Offload this layer's data to CPU device."""
if self.is_initialized:
self.keys ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/cache_utils.py |
Document all endpoints with docstrings | # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 Google AI, Google Brain and 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
#
# ... | --- +++ @@ -84,6 +84,62 @@ local_files_only: bool = False,
**kwargs,
):
+ """
+ Loads the video processor configuration from a pretrained model video processor configuration.
+
+ Args:
+ pretrained_model_name_or_path (`str` or `os.PathLike`):
+ This can be either:
+
+ - a... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/auto/video_processing.py |
Turn comments into proper 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... | --- +++ @@ -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.
+"""Unified Checkpoint Dynamic Loading Functions"""
import copy
import json
@@ -72,6 +73,11 @@
def create_... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/unified_checkpoint/load_dynamic.py |
Add docstrings with type hints explained | # coding=utf-8
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this fi... | --- +++ @@ -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.
+""" Configuration base class and utilities."""
from __future__ import annotations
import copy
@@ -42,6 +43,16... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/configuration_utils.py |
Add docstrings to my Python code | # 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,10 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Audio processing functions to extract features from audio waveforms. This code is pure numpy to support all frameworks
+and remove unnecessary dependencies.
+"""
import warnings
f... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/audio_utils.py |
Generate missing documentation strings | # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2022 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.... | --- +++ @@ -22,12 +22,23 @@
class PaddleGELUTanh(nn.Layer):
+ """
+ A fast C implementation of the tanh approximation of the GeLU activation function. See
+ https://huggingface.co/papers/1606.08415.
+
+ This implementation is equivalent to NewGELU and FastGELU but much faster. However, it is not an exac... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/activations.py |
Help me comply with documentation standards | # 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,11 +12,18 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+""" Ernie4_5 model configuration."""
from ..configuration_utils import PretrainedConfig
from ..modeling_rope_utils import rope_config_validation, standardize_rope_params
class Er... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5/configuration.py |
Write reusable docstrings | # Copyright 2020-present the HuggingFace Inc. team.
# 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.o... | --- +++ @@ -16,6 +16,9 @@ # This file is modified from
# https://github.com/huggingface/transformers/blob/main/src/transformers/trainer_utils.py
+"""
+Utilities for the Trainer class.
+"""
from __future__ import annotations
import datetime
@@ -94,6 +97,9 @@
def mock_offload_optimizer():
+ """
+ mock o... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/trainer_utils.py |
Write proper docstrings for these 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... | --- +++ @@ -309,6 +309,12 @@ def load_state_dict_from_checkpoint_with_reshard(
self, checkpoint, base_weight_name, model_wrapped, opt_state_dict=None
):
+ """load state_dict from_checkpoint with reshard, Only load model state dict.
+ Args:
+ checkpoint (str): The directory of ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/utils/sharding_io.py |
Write docstrings for utility 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... | --- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""Paddle Ernie model."""
import math
from typing import Optional, Tuple
@@ -47,12 +48,32 @@
def rotate_half(x):
+ """Rotates half the hidden dims of the input."""
x1 = x[... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5/modeling.py |
Generate consistent documentation across files | # Copyright 2020-present the HuggingFace Inc. team.
# 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.apache.org/l... | --- +++ @@ -65,6 +65,9 @@
def default_logdir() -> str:
+ """
+ Same default
+ """
import socket
from datetime import datetime
@@ -74,6 +77,369 @@
@dataclass
class TrainingArguments:
+ """
+ TrainingArguments is the subset of the arguments we use in our example scripts **which relate to... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/training_args.py |
Add docstrings that explain purpose and usage | # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
# Copyright (c) 2023 DeepSeek. 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 architectural differ... | --- +++ @@ -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 DeepSeek model."""
from __future__ import annotations
@@ -158,6 +159,17 @@ config: Optiona... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/deepseek_v3/modeling.py |
Create documentation strings for testing functions | # 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 app... | --- +++ @@ -225,6 +225,9 @@ )
def _get_band_mask(self, blocked_query_mask, blocked_key_mask, batch_size, sequence_length):
+ """
+ Return second mask: [B, 1, L-G, bs, G+W]
+ """
GB = self.num_global_blocks_back
GF = self.num_global_blocks_front
G = self.num... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/attention_utils.py |
Generate consistent 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... | --- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Common distributed utils.
+"""
import paddle
import paddle.nn.functional as F
@@ -63,6 +66,9 @@
def get_hcg():
+ """
+ Get hybrid communicate group.
+ """
retur... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/distributed/common_dist_utils.py |
Add missing documentation to my Python 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... | --- +++ @@ -96,12 +96,16 @@
def md5(tensor):
+ """debug use"""
numpy_array = tensor.numpy()
array_bytes = numpy_array.tobytes()
return hashlib.md5(array_bytes).hexdigest()
class ZCCTaskType(Enum):
+ """
+ TaskType defines the type of tasks that can be executed by the ZeroCostCheckpointW... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/utils/zero_cost_checkpoint.py |
Document functions with detailed explanations | # Copyright 2020-present the HuggingFace Inc. team.
# 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.o... | --- +++ @@ -15,6 +15,9 @@
# This file is modified from
# https://github.com/huggingface/transformers/blob/main/src/transformers/trainer_callback.py
+"""
+Callbacks to use with the Trainer class and customize the training loop.
+"""
import dataclasses
import json
import os
@@ -70,6 +73,43 @@
@dataclass
class T... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/trainer/trainer_callback.py |
Add docstrings to incomplete code | # 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... | --- +++ @@ -96,6 +96,14 @@
def tensor_summary(tensor: Union[str, Tensor, PytorchTensor, tuple, list, ndarray]):
+ """get summary of values which can be some of different values
+
+ Args:
+ tensor (ndarray): the source data of tensor which can be: string, Paddle Tensor, Pytorch Tensor, tuple/list tensor... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/conversion_utils.py |
Add concise docstrings to each method | # 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 Ernie model"""
import functools
from typing import Optional, Tuple
@@ -58,6 +59,25 @@
def calc_... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/modeling.py |
Generate docstrings for this script | # 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... | --- +++ @@ -67,10 +67,26 @@
class SimpleInfclLoss(nn.Layer):
def __init__(self, inf_cl_head_dim=64):
+ """
+ Initializes the Simple Inf_cl Loss class.
+
+ Args:
+ inf_cl_head_dim (int, optional): Dimension of the projection head. Default is 64.
+ """
super().__init... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/contrastive_loss.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... | --- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""Paddle Ernie model"""
import contextlib
import math
@@ -92,6 +93,23 @@
@dataclass
class BaseModelOutputWithPastAndCrossAttentions(_BaseModelOutput):
+ """
+ Base class for... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/modeling_moe.py |
Expand my code with proper documentation strings | # 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,9 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+docstring
+"""
import paddle
@@ -23,6 +26,29 @@
def parse_args(args, mtp_enable=False):
+ """
+ Parses input arguments and converts them into model-ready format.
+
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/modeling_moe_pp.py |
Fill in missing docstrings in my code | # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 Google AI, Google Brain and 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
#
# ... | --- +++ @@ -112,6 +112,11 @@
def get_name_mapping(task="Model"):
+ """
+ Task can be 'Backbone', 'Model', 'ForPretraining', 'ForSequenceClassification', 'ForTokenClassification',
+ 'ForQuestionAnswering', 'ForMultipleChoice', 'ForMaskedLM', 'ForCausalLM', 'Encoder', 'Decoder',
+ 'Generator', 'Discrimina... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/auto/modeling.py |
Add professional docstrings to my codebase | # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 Google AI, Google Brain and 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
#
# ... | --- +++ @@ -104,6 +104,62 @@ local_files_only: bool = False,
**kwargs,
):
+ """
+ Loads the image processor configuration from a pretrained model image processor configuration.
+
+ Args:
+ pretrained_model_name_or_path (`str` or `os.PathLike`):
+ This can be either:
+
+ -... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/auto/image_processing.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... | --- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+top2gate
+"""
from functools import partial
from typing import Tuple
@@ -31,12 +34,37 @@
def masked_fill(x, mask, value):
+ """
+ Fills elements of the input tensor wit... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/moe/topk_gate.py |
Generate docstrings for this script | # Copyright 2018 Google AI, Google Brain and 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.apache.org/licenses/LICENSE-2.0
#
# Unless required ... | --- +++ @@ -101,6 +101,7 @@
def config_class_to_model_type(config):
+ """Converts a config class name to the corresponding model type"""
for key, cls in CONFIG_MAPPING_NAMES.items():
if cls == config:
return key
@@ -112,6 +113,9 @@
class _LazyConfigMapping(OrderedDict):
+ """
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/auto/configuration.py |
Add inline docstrings for readability | # 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.
+""" Ernie4_5_Moe model configuration """
import json
from typing import Optional, Union
@@ -22,6 +23,12 @@
class Ernie4_5_MoeConfig(PretrainedConfig):
+ """
+ Configuration ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe/configuration.py |
Help me document legacy Python code | # 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... | --- +++ @@ -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.
+"""refined recompute"""
import inspect
import queue
@@ -32,18 +33,31 @@
def is_second_fwd():
+ """
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/refined_recompute/utils.py |
Add docstrings including usage examples | # 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.
+"""Paddle Ernie4_5_Moe model"""
import math
from copy import deepcopy
@@ -110,6 +111,17 @@ config: Optional[Ernie4_5_MoeConfig] = None,
seq_len: Optional[int] = None,... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe/modeling.py |
Annotate my 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... | --- +++ @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""_summary_
+
+Returns:
+ _type_: _description_
+"""
import inspect
import itertools
@@ -44,8 +49,19 @@
class MoEStatics(nn.Layer):
+ """
+ Stores MoE (Mixture of Exper... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/moe/moe_layer.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... | --- +++ @@ -13,6 +13,9 @@ # limitations under the License.
+"""
+moe_layer_all_gather
+"""
import inspect
from typing import Callable, Dict, List, Optional, Tuple
@@ -46,6 +49,17 @@
def allgather_async(input, group=None):
+ """Perform asynchronous All-Gather operation for model parallelism.
+
+ Args:
... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/moe/moe_all_gather_layer.py |
Create docstrings for API functions | # 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,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.
+"""Processing functions for image and video inputs for ERNIE4.5-MOE-VL."""
import base64
import datetime
@@ -... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/vision_process.py |
Help me comply with documentation standards | # 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... | --- +++ @@ -26,14 +26,32 @@
def barrier_ep(ep_group):
+ """barrier_ep"""
paddle.distributed.barrier(ep_group)
def get_hidden_bytes(x: paddle.Tensor) -> int:
+ """Calculate the number of hidden bytes for a tensor.
+
+ Args:
+ x (paddle.Tensor): Input tensor
+
+ Returns:
+ int: Num... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/fused_a2a.py |
Add well-formatted docstrings | # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2018 Google AI, Google Brain and 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
#
# ... | --- +++ @@ -40,6 +40,13 @@
class _LazyAutoMapping(OrderedDict):
+ """
+ " A mapping config to object (model or tokenizer for instance) that will load keys and values when it is accessed.
+
+ Args:
+ - config_mapping: The map model type to config class
+ - model_mapping: The map model type to ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/auto/factory.py |
Add standardized docstrings across the file | # 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... | --- +++ @@ -31,12 +31,27 @@
class BatchFeature(UserDict):
+ r"""
+ Holds the feature extractor specific `__call__` methods.
+ This class is derived from a python dictionary and can be used as a dictionary.
+ Args:
+ data (`dict`):
+ Dictionary of lists/arrays/tensors returned by the __... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/feature_extraction_utils.py |
Add docstrings to improve collaboration | # 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 applicab... | --- +++ @@ -76,6 +76,7 @@
def _get_fp8_weight_and_scale(weight, stacked=False, transpose=False):
+ """_get_fp8_weight_and_scale"""
if stacked:
if transpose:
fp8_weight, fp8_scale = weight.fp8_weight_stacked_transpose, weight.fp8_scale_stacked_transpose
@@ -154,6 +155,7 @@
@static... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/fp8_utils.py |
Write Python docstrings for this snippet | # 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.
+""" Ernie model configuration"""
import json
from typing import Optional, Union
@@ -49,6 +50,12 @@
class Ernie4_5_Config(PretrainedConfig):
+ """
+ Configuration class for E... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/configuration.py |
Generate helpful docstrings for debugging | # Copyright (c) 2025 Baidu, Inc. 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 applicable law ... | --- +++ @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""Tokenization classes for Ernie_45T_VL."""
import os
from shutil import copyfile
@@ -27,6 +28,9 @@
class Ernie4_5_VLTokenizer(PreTrainedTokenizer):
+ """
+ Ernie4_5_VLToke... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/tokenizer.py |
Write docstrings that follow conventions | # 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 used in training process"""
import paddle
from paddle import distributed as dist
@@ -19,6 +20,10 @@
def all_gather_varlen(input, indices, gr... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/comm_utils.py |
Write clean docstrings for readability | # 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,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 ERNIE4.5-MOE-VL."""
import math
from typing import List, Optional, Union
@@ -53,... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/image_processor.py |
Create docstrings for each class method | # coding=utf-8
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2025 The ZhipuAI Inc. team and 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
# origin... | --- +++ @@ -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 GLM4.5-VL."""
from typing import Optional, Union
@@ -54,6 +55,19 @@
class Glm4vPr... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm4v_moe/processor.py |
Add docstrings that explain logic | # 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.
+"""Rebalance input tensors by token_type_ids in a SequenceParallel communication group"""
import heapq
from collections import namedtuple
@@ -27,8 +28,16 @@
class MaxHeap:
+ ""... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/longcontext_ops.py |
Document all endpoints with docstrings | # coding=utf-8
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2025 The ZhipuAI Inc. team and 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
# origin... | --- +++ @@ -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 GLM-4.1V."""
import math
from typing import Optional, Union
@@ -75,6 +76,14... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm4v_moe/image_processor_fast.py |
Document my Python code with docstrings | # 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... | --- +++ @@ -49,6 +49,9 @@
@dataclass
class MoeModelOutputWithPast(ModelOutput):
+ """
+ Base class for model's outputs, with potential hidden states and attentions.
+ """
last_hidden_state: Optional[paddle.FloatTensor] = None
past_key_values: Optional[Cache] = None
@@ -59,6 +62,15 @@
@dataclas... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm4v_moe/modeling.py |
Add verbose docstrings with examples | # 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.
+""" Ernie4_5_VLMoeForConditionalGenerationPipe """
import ast
import contextlib
@@ -140,6 +141,9 @@
class ErniePretrainingCriterionPipe(ErniePretrainingCriterion):
+ """
+ E... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/modeling_moe_vl_pp.py |
Add docstrings for production code | # coding=utf-8
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
# Copyright 2025 The ZhipuAI Inc. team and 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
# origin... | --- +++ @@ -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 GLM-4.1V."""
import math
from typing import Optional, Union
@@ -81,6 +82,10 @@ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/glm4v_moe/video_processor.py |
Create structured documentation for my script | # 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,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 ERNIE4.5-MOE-VL."""
import copy
import io
@@ -36,6 +37,10 @@
class Ernie4_5_VLProc... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/processor.py |
Write docstrings describing functionality | # 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.
+"""Paddle Ernie VL model"""
import contextlib
import json
@@ -61,6 +62,7 @@
class TokenType:
+ """token type definition"""
text = 0
image = 1
@@ -72,6 +74,9 @@
... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/modeling_moe_vl.py |
Add docstrings with type hints explained | # 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... | --- +++ @@ -40,10 +40,16 @@
def is_casual_mask(attention_mask):
+ """
+ Upper triangular of attention_mask equals to attention_mask is casual
+ """
return (paddle.triu(attention_mask) == attention_mask).all().item()
def _make_causal_mask(input_ids_shape, past_key_values_length):
+ """
+ Mak... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/gpt_oss/modeling.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... | --- +++ @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Common fusion operators.
+"""
import paddle
import paddle.nn.functional as F
@@ -43,6 +46,29 @@ attn_mask_start_row_indices=None,
rr_flash_attn=None,
):
+ """
+ P... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/fusion_ops/common_fusion_ops.py |
Document functions with clear intent | # 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... | --- +++ @@ -45,6 +45,18 @@ channel_dim: Union[ChannelDimension, str],
input_channel_dim: Optional[Union[ChannelDimension, str]] = None,
) -> np.ndarray:
+ """
+ Converts `image` to the channel dimension format specified by `channel_dim`.
+
+ Args:
+ image (`numpy.ndarray`):
+ The im... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/image_transforms.py |
Generate helpful docstrings for debugging | # 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... | --- +++ @@ -29,6 +29,9 @@ if not hasattr(paddle.Tensor, "contiguous"):
def contiguous(self):
+ """
+ Make the tensor contiguous.
+ """
return self
paddle.Tensor.contiguous = contiguous
@@ -37,6 +40,9 @@ if not hasattr(paddle.Tensor, "_md5sum"):
def _md5sum(self):
+ ... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/sequence_parallel_utils.py |
Add docstrings to improve code quality | # 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.
+""" Gemma3 model configuration """
from typing import TYPE_CHECKING, Any, Optional, Union
from ...utils.log import logger
@@ -24,6 +25,125 @@
class Gemma3TextConfig(PretrainedConf... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/gemma3_text/configuration.py |
Add minimal docstrings for each function | # 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.
+""" Ernie model configuration"""
from paddleformers.transformers.configuration_utils import PretrainedConfig
@@ -21,6 +22,11 @@
class DFNRopeVisionTransformerConfig(PretrainedCon... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/ernie4_5_moe_vl/model/dfnrope/configuration.py |
Generate helpful docstrings for debugging | # 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... | --- +++ @@ -124,6 +124,17 @@ sample_indices: list = None,
return_video: bool = False,
) -> dict:
+ """read video using torchcodec.decoders.VideoDecoder(via Paddle Proxy)
+
+ Args:
+ ele (dict): a dict contains the configuration of video.
+ support keys:
+ - video: the path of vi... | https://raw.githubusercontent.com/PaddlePaddle/PaddleFormers/HEAD/paddleformers/transformers/kimi_k25/media_utils.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.