repo_id
stringlengths
15
89
file_path
stringlengths
27
180
content
stringlengths
1
2.23M
__index_level_0__
int64
0
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/utils/checkpoint_saver.py
""" Checkpoint Saver Track top-n training checkpoints and maintain recovery checkpoints on specified intervals. Hacked together by / Copyright 2020 Ross Wightman """ import glob import operator import os import logging import torch from .model import unwrap_model, get_state_dict _logger = logging.getLogger(__nam...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/utils/cuda.py
""" CUDA / AMP utils Hacked together by / Copyright 2020 Ross Wightman """ import torch try: from apex import amp has_apex = True except ImportError: amp = None has_apex = False from .clip_grad import dispatch_clip_grad class ApexScaler: state_dict_key = "amp" def __call__( sel...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/utils/random.py
import random import numpy as np import torch def random_seed(seed=42, rank=0): torch.manual_seed(seed + rank) np.random.seed(seed + rank) random.seed(seed + rank)
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/asymmetric_loss.py
import torch import torch.nn as nn class AsymmetricLossMultiLabel(nn.Module): def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): super(AsymmetricLossMultiLabel, self).__init__() self.gamma_neg = gamma_neg self.gamma_pos = gamma_pos ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/cross_entropy.py
""" Cross Entropy w/ smoothing or soft targets Hacked together by / Copyright 2021 Ross Wightman """ import torch import torch.nn as nn import torch.nn.functional as F class LabelSmoothingCrossEntropy(nn.Module): """ NLL loss with label smoothing. """ def __init__(self, smoothing=0.1): super(Lab...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/jsd.py
import torch import torch.nn as nn import torch.nn.functional as F from .cross_entropy import LabelSmoothingCrossEntropy class JsdCrossEntropy(nn.Module): """ Jensen-Shannon Divergence + Cross-Entropy Loss Based on impl here: https://github.com/google-research/augmix/blob/master/imagenet.py From paper: ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/__init__.py
from .asymmetric_loss import AsymmetricLossMultiLabel, AsymmetricLossSingleLabel from .binary_cross_entropy import BinaryCrossEntropy from .cross_entropy import LabelSmoothingCrossEntropy, SoftTargetCrossEntropy from .jsd import JsdCrossEntropy
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/binary_cross_entropy.py
""" Binary Cross Entropy w/ a few extras Hacked together by / Copyright 2021 Ross Wightman """ from typing import Optional import torch import torch.nn as nn import torch.nn.functional as F class BinaryCrossEntropy(nn.Module): """ BCE with optional one-hot from dense targets, label smoothing, thresholding N...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/lion.py
""" Lion Optimizer Paper: `Symbolic Discovery of Optimization Algorithms` - https://arxiv.org/abs/2302.06675 Original Impl: https://github.com/google/automl/tree/master/lion """ # Copyright 2023 Google Research. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use t...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/adahessian.py
""" AdaHessian Optimizer Lifted from https://github.com/davda54/ada-hessian/blob/master/ada_hessian.py Originally licensed MIT, Copyright 2020, David Samuel """ import torch class Adahessian(torch.optim.Optimizer): """ Implements the AdaHessian algorithm from "ADAHESSIAN: An Adaptive Second OrderOptimizer fo...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/nadam.py
import math import torch from torch.optim.optimizer import Optimizer class Nadam(Optimizer): """Implements Nadam algorithm (a variant of Adam based on Nesterov momentum). It has been proposed in `Incorporating Nesterov Momentum into Adam`__. Arguments: params (iterable): iterable of parameters ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/lookahead.py
""" Lookahead Optimizer Wrapper. Implementation modified from: https://github.com/alphadl/lookahead.pytorch Paper: `Lookahead Optimizer: k steps forward, 1 step back` - https://arxiv.org/abs/1907.08610 Hacked together by / Copyright 2020 Ross Wightman """ from collections import OrderedDict from typing import Callable...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/rmsprop_tf.py
""" RMSProp modified to behave like Tensorflow impl Originally cut & paste from PyTorch RMSProp https://github.com/pytorch/pytorch/blob/063946d2b3f3f1e953a2a3b54e0b34f1393de295/torch/optim/rmsprop.py Licensed under BSD-Clause 3 (ish), https://github.com/pytorch/pytorch/blob/master/LICENSE Modifications Copyright 2021...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/lars.py
""" PyTorch LARS / LARC Optimizer An implementation of LARS (SGD) + LARC in PyTorch Based on: * PyTorch SGD: https://github.com/pytorch/pytorch/blob/1.7/torch/optim/sgd.py#L100 * NVIDIA APEX LARC: https://github.com/NVIDIA/apex/blob/master/apex/parallel/LARC.py Additional cleanup and modifications to properly su...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/madgrad.py
""" PyTorch MADGRAD optimizer MADGRAD: https://arxiv.org/abs/2101.11075 Code from: https://github.com/facebookresearch/madgrad """ # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import ma...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/sgdp.py
""" SGDP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/sgdp.py Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217 Code: https://github.com/clovaai/AdamP Copyright (c) 2020-present NAVER Corp. MIT license """ import ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/adamw.py
""" AdamW Optimizer Impl copied from PyTorch master NOTE: Builtin optim.AdamW is used by the factory, this impl only serves as a Python based reference, will be removed someday """ import math import torch from torch.optim.optimizer import Optimizer class AdamW(Optimizer): r"""Implements AdamW algorithm. Th...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/nvnovograd.py
""" Nvidia NovoGrad Optimizer. Original impl by Nvidia from Jasper example: - https://github.com/NVIDIA/DeepLearningExamples/blob/master/PyTorch/SpeechRecognition/Jasper Paper: `Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks` - https://arxiv.org/abs/1905.11286 """ im...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/adamp.py
""" AdamP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/adamp.py Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217 Code: https://github.com/clovaai/AdamP Copyright (c) 2020-present NAVER Corp. MIT license """ impor...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/lamb.py
""" PyTorch Lamb optimizer w/ behaviour similar to NVIDIA FusedLamb This optimizer code was adapted from the following (starting with latest) * https://github.com/HabanaAI/Model-References/blob/2b435114fe8e31f159b1d3063b8280ae37af7423/PyTorch/nlp/bert/pretraining/lamb.py * https://github.com/NVIDIA/DeepLearningExample...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/nadamw.py
""" NAdamW Optimizer Based on simplified algorithm in https://github.com/mlcommons/algorithmic-efficiency/tree/main/baselines/nadamw Added multi-tensor (foreach) path. """ import math from typing import List, Optional import torch from torch import Tensor # Modified from github.com/pytorch/pytorch/blob/v1.12.1/tor...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/radam.py
"""RAdam Optimizer. Implementation lifted from: https://github.com/LiyuanLucasLiu/RAdam Paper: `On the Variance of the Adaptive Learning Rate and Beyond` - https://arxiv.org/abs/1908.03265 """ import math import torch from torch.optim.optimizer import Optimizer class RAdam(Optimizer): def __init__(self, params, ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/__init__.py
from .adabelief import AdaBelief from .adafactor import Adafactor from .adahessian import Adahessian from .adamp import AdamP from .adamw import AdamW from .adan import Adan from .lamb import Lamb from .lars import Lars from .lookahead import Lookahead from .madgrad import MADGRAD from .nadam import Nadam from .nvnovog...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/adabelief.py
import math import torch from torch.optim.optimizer import Optimizer class AdaBelief(Optimizer): r"""Implements AdaBelief algorithm. Modified from Adam in PyTorch Arguments: params (iterable): iterable of parameters to optimize or dicts defining parameter groups lr (float, optiona...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/adafactor.py
""" Adafactor Optimizer Lifted from https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py Original header/copyright below. """ # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/optim_factory.py
""" Optimizer Factory w/ Custom Weight Decay Hacked together by / Copyright 2021 Ross Wightman """ import logging from itertools import islice from typing import Optional, Callable, Tuple import torch import torch.nn as nn import torch.optim as optim from timm.models import group_parameters from .adabelief import Ad...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/optim/adan.py
""" Adan Optimizer Adan: Adaptive Nesterov Momentum Algorithm for Faster Optimizing Deep Models[J]. arXiv preprint arXiv:2208.06677, 2022. https://arxiv.org/abs/2208.06677 Implementation adapted from https://github.com/sail-sg/Adan """ import math import torch from torch.optim import Optimizer class Adan(Opt...
0
hf_public_repos/pytorch-image-models
hf_public_repos/pytorch-image-models/convert/convert_from_mxnet.py
import argparse import hashlib import os import mxnet as mx import gluoncv import torch from timm import create_model parser = argparse.ArgumentParser(description='Convert from MXNet') parser.add_argument('--model', default='all', type=str, metavar='MODEL', help='Name of model to train (default: "...
0
hf_public_repos/pytorch-image-models
hf_public_repos/pytorch-image-models/convert/convert_nest_flax.py
""" Convert weights from https://github.com/google-research/nested-transformer NOTE: You'll need https://github.com/google/CommonLoopUtils, not included in requirements.txt """ import sys import numpy as np import torch from clu import checkpoint arch_depths = { 'nest_base': [2, 2, 20], 'nest_small': [2, 2...
0
hf_public_repos
hf_public_repos/trl/Makefile
.PHONY: test precommit benchmark_core benchmark_aux check_dirs := examples tests trl test: python -m pytest -n auto --dist=loadfile -s -v ./tests/ precommit: pre-commit run --all-files benchmark_core: bash ./benchmark/benchmark_core.sh benchmark_aux: bash ./benchmark/benchmark_aux.sh
0
hf_public_repos
hf_public_repos/trl/MANIFEST.in
include settings.ini include LICENSE include CONTRIBUTING.md include README.md recursive-exclude * __pycache__
0
hf_public_repos
hf_public_repos/trl/LICENSE
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, ...
0
hf_public_repos
hf_public_repos/trl/README.md
<div style="text-align: center"> <img src="https://huggingface.co/datasets/trl-internal-testing/example-images/resolve/main/images/trl_banner_dark.png"> </div> # TRL - Transformer Reinforcement Learning > Full stack transformer language models with reinforcement learning. <p align="center"> <a href="https://githu...
0
hf_public_repos
hf_public_repos/trl/CONTRIBUTING.md
# How to contribute ## How to get started Before you start contributing make sure you installed all the dev tools: ```bash pip install -e ".[dev]" ``` ## Did you find a bug? * Ensure the bug was not already reported by searching on GitHub under Issues. * If you're unable to find an open issue addressing the proble...
0
hf_public_repos
hf_public_repos/trl/.pre-commit-config.yaml
repos: - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: - id: isort args: - --profile=black - --skip-glob=wandb/**/* - --thirdparty=wandb - repo: https://github.com/myint/autoflake rev: v1.4 hooks: - id: autoflake args: - -...
0
hf_public_repos
hf_public_repos/trl/setup.py
""" trl is an open library for RL with transformer models. Note: VERSION needs to be formatted following the MAJOR.MINOR.PATCH convention (we need to follow this convention to be able to retrieve versioned scripts) Simple check list for release from AllenNLP repo: https://github.com/allenai/allennlp/blob/maste...
0
hf_public_repos
hf_public_repos/trl/requirements.txt
datasets>=1.17.0 torch>=1.4.0 tqdm transformers accelerate peft>=0.3.0 tyro>=0.5.7
0
hf_public_repos
hf_public_repos/trl/setup.cfg
[metadata] license_file = LICENSE [isort] ensure_newline_before_comments = True force_grid_wrap = 0 include_trailing_comma = True line_length = 119 lines_after_imports = 2 multi_line_output = 3 use_parentheses = True
0
hf_public_repos
hf_public_repos/trl/CITATION.cff
cff-version: 1.2.0 title: 'TRL: Transformer Reinforcement Learning' message: >- If you use this software, please cite it using the metadata from this file. type: software authors: - given-names: Leandro family-names: von Werra - given-names: Younes family-names: Belkada - given-names: Lewis family...
0
hf_public_repos
hf_public_repos/trl/pyproject.toml
[tool.black] line-length = 119 target-version = ['py38'] [tool.ruff] ignore = ["E501", "E741", "W605"] select = ["E", "F", "I", "W"] line-length = 119 # Ignore import violations in all `__init__.py` files. [tool.ruff.per-file-ignores] "__init__.py" = ["E402", "F401", "F403", "F811"] [tool.ruff.isort] lines-after-imp...
0
hf_public_repos/trl
hf_public_repos/trl/trl/import_utils.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/trl/__init__.py
# flake8: noqa __version__ = "0.7.5.dev0" from .core import set_seed from .environment import TextEnvironment, TextHistory from .extras import BestOfNSampler from .import_utils import is_diffusers_available, is_peft_available, is_wandb_available, is_xpu_available from .models import ( AutoModelForCausalLMWithValu...
0
hf_public_repos/trl
hf_public_repos/trl/trl/core.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/models/modeling_sd_base.py
# Copyright 2023 DDPO-pytorch authors (Kevin Black), The HuggingFace Team, metric-space. 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/lic...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/models/modeling_base.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/models/modeling_value_head.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/models/__init__.py
# flake8: noqa # 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.apache.org/licenses/LICENSE-2.0 # # Unless requi...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/training_configs.py
# coding=utf-8 # coding=utf-8 # Copyright 2023 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/licenses/LICENSE-2.0 # ...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/reward_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/ppo_trainer.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/iterative_sft_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/utils.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/ddpo_trainer.py
# Copyright 2023 DDPO-pytorch authors (Kevin Black), metric-space, 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/lic...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/ppo_config.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/base.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/ddpo_config.py
import os import sys import warnings from dataclasses import dataclass, field from typing import Literal, Optional from ..core import flatten_dict from ..import_utils import is_bitsandbytes_available, is_torchvision_available @dataclass class DDPOConfig: """ Configuration class for DDPOTrainer """ #...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/sft_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/__init__.py
# flake8: noqa # 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.apache.org/licenses/LICENSE-2.0 # # Unless requi...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/trainer/dpo_trainer.py
# DPO Authors: Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, and Chelsea Finn 2023 # Copyright 2023 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. # ...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/environment/__init__.py
# flake8: noqa from .base_environment import TextEnvironment, TextHistory
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/environment/base_environment.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/extras/best_of_n_sampler.py
from typing import Any, Callable, List, Optional, Union import torch from transformers import GenerationConfig, PreTrainedTokenizer, PreTrainedTokenizerFast from ..core import set_seed from ..models import SUPPORTED_ARCHITECTURES, PreTrainedModelWrapper class BestOfNSampler(object): def __init__( self, ...
0
hf_public_repos/trl/trl
hf_public_repos/trl/trl/extras/__init__.py
# flake8: noqa # 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.apache.org/licenses/LICENSE-2.0 # # Unless requi...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark_level3.sh
## w/ and w/o gradient accumulation python benchmark/benchmark.py \ --command "python examples/scripts/ppo.py --ppo_config.exp_name ppo_step_grad_accu --ppo_config.mini_batch_size 1 --ppo_config.gradient_accumulation_steps 128 --ppo_config.log_with wandb" \ --num-seeds 3 \ --start-seed 1 \ --workers 10 ...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark_level1_plot.sh
# pip install openrlbenchmark==0.2.1a5 # see https://github.com/openrlbenchmark/openrlbenchmark#get-started for documentation echo "we deal with $TAGS_STRING" python -m openrlbenchmark.rlops_multi_metrics \ --filters '?we=huggingface&wpn=trl&xaxis=_step&ceik=trl_ppo_trainer_config.value.reward_model&cen=trl_ppo_tr...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/plot.sh
# pip install openrlbenchmark==0.2.1a5 # see https://github.com/openrlbenchmark/openrlbenchmark#get-started for documentation BASELINE_PR_TAG=v0.4.7-55-g110e672 BASELINE_PR_NAME=PR-662 python -m openrlbenchmark.rlops_multi_metrics \ --filters '?we=huggingface&wpn=trl&xaxis=_step&ceik=trl_ppo_trainer_config.value.r...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark.py
import argparse import math import os import shlex import subprocess import uuid from distutils.util import strtobool import requests def parse_args(): # fmt: off parser = argparse.ArgumentParser() parser.add_argument("--command", type=str, default="", help="the command to run") parser.add_ar...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/upload_benchmark.py
from dataclasses import dataclass import tyro from huggingface_hub import HfApi @dataclass class Args: folder_path: str = "benchmark/trl" path_in_repo: str = "images/benchmark" repo_id: str = "trl-internal-testing/example-images" repo_type: str = "dataset" args = tyro.cli(Args) api = HfApi() api.u...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/post_github_comment.py
import json import os from ghapi.all import GhApi FOLDER_STRING = os.environ.get("FOLDER_STRING", "") folder = f"benchmark/trl/{FOLDER_STRING}" host_url = f"https://huggingface.co/datasets/trl-internal-testing/example-images/resolve/main/images/benchmark/{FOLDER_STRING}" # Create a GitHub API instance github_contex...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark_level1.sh
# hello world experiment python benchmark/benchmark.py \ --command "python examples/scripts/ppo.py --ppo_config.log_with wandb" \ --num-seeds 3 \ --start-seed 1 \ --workers 10 \ --slurm-nodes 1 \ --slurm-gpus-per-task 1 \ --slurm-ntasks 1 \ --slurm-total-cpus 12 \ --slurm-template-pa...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark_level2.sh
# compound experiments: gpt2xl + grad_accu python benchmark/benchmark.py \ --command "python examples/scripts/ppo.py --ppo_config.exp_name ppo_gpt2xl_grad_accu --ppo_config.model_name gpt2-xl --ppo_config.mini_batch_size 16 --ppo_config.gradient_accumulation_steps 8 --ppo_config.log_with wandb" \ --num-seeds 3 ...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/trl.slurm_template
#!/bin/bash #SBATCH --job-name=trl #SBATCH --partition=production-cluster #SBATCH --gpus-per-task={{gpus_per_task}} #SBATCH --cpus-per-gpu={{cpus_per_gpu}} #SBATCH --ntasks={{ntasks}} #SBATCH --output=slurm/logs/%x_%j.out #SBATCH --array={{array}} #SBATCH --exclude=ip-26-0-156-239,ip-26-0-148-151,ip-26-0-146-212,ip-26-...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/post_github_comment.sbatch
#!/bin/bash #SBATCH --job-name=trl #SBATCH --partition=production-cluster #SBATCH --ntasks=1 #SBATCH --output=slurm/logs/%x_%j.out sleep 2m bash $BENCHMARK_PLOT_SCRIPT srun python benchmark/post_github_comment.py
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark_and_report.sh
#### Step 1: create a work directory: # this is necessary because another github action job will remove # the entire directory, which slurm depends on. # https://stackoverflow.com/questions/4632028/how-to-create-a-temporary-directory MY_SLURM_TMP_DIR=/fsx/costa/slurm_tmpdir mkdir -p $MY_SLURM_TMP_DIR WORK_DIR=`mktemp -...
0
hf_public_repos/trl
hf_public_repos/trl/benchmark/benchmark_level2_plot.sh
# pip install openrlbenchmark==0.2.1a5 # see https://github.com/openrlbenchmark/openrlbenchmark#get-started for documentation echo "we deal with $TAGS_STRING" python -m openrlbenchmark.rlops_multi_metrics \ --filters '?we=huggingface&wpn=trl&xaxis=_step&ceik=trl_ppo_trainer_config.value.reward_model&cen=trl_ppo_tr...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_ddpo_trainer.py
# Copyright 2023 metric-space, 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/licenses/LICENSE-2.0 # # Unless require...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_modeling_value_head.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/testing_constants.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_best_of_n_sampler.py
import unittest import torch from transformers import AutoTokenizer, GenerationConfig from trl import AutoModelForCausalLMWithValueHead from trl.core import LengthSampler from trl.extras import BestOfNSampler def queries_to_scores(list_of_strings): return [torch.rand(1).item() for _ in list_of_strings] class ...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_sft_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_reward_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_peft_models.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_core.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_data_collator_completion_only.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_no_peft.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_dpo_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_environments.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_e2e.py
import subprocess def test_hello_world(): subprocess.run( "python examples/hello_world.py", shell=True, check=True, )
0
hf_public_repos/trl
hf_public_repos/trl/tests/testing_utils.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_iterative_sft_trainer.py
# Copyright 2023 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/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl
hf_public_repos/trl/tests/test_ppo_trainer.py
# 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.apache.org/licenses/LICENSE-2.0 # # Unless required by applicabl...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/quickstart.mdx
# Quickstart ## How does it work? Fine-tuning a language model via PPO consists of roughly three steps: 1. **Rollout**: The language model generates a response or continuation based on a query which could be the start of a sentence. 2. **Evaluation**: The query and response are evaluated with a function, model, huma...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/how_to_train.md
# Training FAQ ## What Metrics Should I Look at? When performing classical supervised fine-tuning of language models, the loss (especially the validation loss) serves as a good indicator of the training progress. However, in Reinforcement Learning (RL), the loss becomes less informative about the model's performance,...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/ddpo_trainer.mdx
# Denoising Diffusion Policy Optimization ## The why | Before | After DDPO finetuning | | --- | --- | | <div style="text-align: center"><img src="https://huggingface.co/datasets/trl-internal-testing/example-images/resolve/main/images/pre_squirrel.png"/></div> | <div style="text-align: center"><img src="https://huggin...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/sentiment_tuning.mdx
# Sentiment Tuning Examples The notebooks and scripts in this examples show how to fine-tune a model with a sentiment classifier (such as `lvwerra/distilbert-imdb`). Here's an overview of the notebooks and scripts in the [trl repository](https://github.com/huggingface/trl/tree/main/examples): | File ...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/_toctree.yml
- sections: - local: index title: TRL - local: quickstart title: Quickstart - local: installation title: Installation - local: how_to_train title: PPO Training FAQ - local: use_model title: Use Trained Models - local: customization title: Customize the Training - local: logging ...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/sft_trainer.mdx
# Supervised Fine-tuning Trainer Supervised fine-tuning (or SFT for short) is a crucial step in RLHF. In TRL we provide an easy-to-use API to create your SFT models and train them with few lines of code on your dataset. Check out a complete flexible example at [`examples/scripts/sft.py`](https://github.com/huggingfa...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/text_environments.md
# Text Environments Text environments provide a learning ground for language agents. It allows a language model to use tools to accomplish a task such as using a Python interpreter to answer math questions or using a search index for trivia questions. Having access to tools allows language models to solve tasks that w...
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/dpo_trainer.mdx
# DPO Trainer TRL supports the DPO Trainer for training language models from preference data, as described in the paper [Direct Preference Optimization: Your Language Model is Secretly a Reward Model](https://arxiv.org/abs/2305.18290) by Rafailov et al., 2023. For a full example have a look at [`examples/scripts/dpo....
0
hf_public_repos/trl/docs
hf_public_repos/trl/docs/source/using_llama_models.mdx
# Using LLaMA models with TRL We've begun rolling out examples to use Meta's LLaMA models in `trl` (see [Meta's LLaMA release](https://ai.facebook.com/blog/large-language-model-llama-meta-ai/) for the original LLaMA model). ## Efficient training strategies Even training the smallest LLaMA model requires an enormous ...
0