python_code
stringlengths
0
456k
from abc import ABC, abstractmethod from typing import Any from chatgpt.experience_maker.base import Experience class ReplayBuffer(ABC): """Replay buffer base class. It stores experience. Args: sample_batch_size (int): Batch size when sampling. limit (int, optional): Limit of number of ex...
from typing import Optional import torch from transformers import BloomConfig, BloomForCausalLM, BloomModel from .actor import Actor class BLOOMActor(Actor): """ BLOOM Actor model. Args: pretrained (str): Pretrained model name or path. config (BloomConfig): Model config. checkpo...
from typing import Optional import torch import torch.nn as nn from transformers import BloomConfig, BloomForCausalLM, BloomModel from .reward_model import RewardModel class BLOOMRM(RewardModel): """ BLOOM Reward model. Args: pretrained (str): Pretrained model name or path. config (Bloo...
from typing import Optional import torch.nn as nn from transformers.models.opt.configuration_opt import OPTConfig from transformers.models.opt.modeling_opt import OPTModel from .reward_model import RewardModel class OPTRM(RewardModel): """ OPT Reward model. Args: pretrained (str): Pretrained mo...
from typing import Any, Callable, Optional import torch import torch.nn as nn try: from transformers.generation_logits_process import ( LogitsProcessorList, TemperatureLogitsWarper, TopKLogitsWarper, TopPLogitsWarper, ) except ImportError: from transformers.generation impor...
from typing import Optional import torch.nn as nn from transformers.models.gpt2.configuration_gpt2 import GPT2Config from transformers.models.gpt2.modeling_gpt2 import GPT2Model from .reward_model import RewardModel class GPTRM(RewardModel): """ GPT Reward model. Args: pretrained (str): Pretrai...
from typing import Optional import torch.nn as nn from transformers.models.opt.configuration_opt import OPTConfig from transformers.models.opt.modeling_opt import OPTModel from .critic import Critic class OPTCritic(Critic): """ OPT Critic model. Args: pretrained (str): Pretrained model name or ...
from typing import Optional import torch import torch.nn as nn from transformers import BloomConfig, BloomForCausalLM, BloomModel from .critic import Critic class BLOOMCritic(Critic): """ BLOOM Critic model. Args: pretrained (str): Pretrained model name or path. config (BloomConfig): Mo...
from .actor import Actor from .bloom_actor import BLOOMActor from .bloom_critic import BLOOMCritic from .bloom_rm import BLOOMRM from .critic import Critic from .gpt_actor import GPTActor from .gpt_critic import GPTCritic from .gpt_rm import GPTRM from .loss import PairWiseLoss, PolicyLoss, PPOPtxActorLoss, ValueLoss f...
from typing import Optional import torch def gpt_prepare_inputs_fn(input_ids: torch.Tensor, past: Optional[torch.Tensor] = None, **kwargs) -> dict: token_type_ids = kwargs.get("token_type_ids", None) # only last token for inputs_ids if past is defined in kwargs if past: input_ids = input_ids[:, -...
from typing import Optional import torch import torch.nn as nn from .utils import masked_mean class GPTLMLoss(nn.Module): """ GPT Language Model Loss """ def __init__(self): super().__init__() self.loss = nn.CrossEntropyLoss() def forward(self, logits: torch.Tensor, labels: tor...
from typing import Optional, Union import loralib as lora import torch import torch.nn as nn import torch.nn.functional as F def compute_approx_kl(log_probs: torch.Tensor, log_probs_base: torch.Tensor, action_mask: Optional[torch.Tensor] = None) -> torch.Tensor: """ ...
from typing import Optional from transformers.models.opt.configuration_opt import OPTConfig from transformers.models.opt.modeling_opt import OPTForCausalLM from .actor import Actor class OPTActor(Actor): """ OPT Actor model. Args: pretrained (str): Pretrained model name or path. config ...
from typing import Optional import torch import torch.nn as nn from .lora import LoRAModule class RewardModel(LoRAModule): """ Reward model base class. Args: model (nn.Module): Reward model. value_head (nn.Module): Value head to get reward score. lora_rank (int): LoRA rank. ...
import math from typing import Optional import loralib as lora import torch import torch.nn as nn import torch.nn.functional as F class LoraLinear(lora.LoRALayer, nn.Module): """Replace in-place ops to out-of-place ops to fit gemini. Convert a torch.nn.Linear to LoraLinear. """ def __init__( sel...
from typing import Optional, Tuple, Union import torch import torch.nn as nn import torch.nn.functional as F from .generation import generate from .lora import LoRAModule from .utils import log_probs_from_logits class Actor(LoRAModule): """ Actor model base class. Args: model (nn.Module): Actor...
from typing import Optional import torch import torch.nn as nn from .lora import LoRAModule from .utils import masked_mean class Critic(LoRAModule): """ Critic model base class. Args: model (nn.Module): Critic model. value_head (nn.Module): Value head to get value. lora_rank (in...
from typing import Optional from transformers.models.gpt2.configuration_gpt2 import GPT2Config from transformers.models.gpt2.modeling_gpt2 import GPT2LMHeadModel from .actor import Actor class GPTActor(Actor): """ GPT Actor model. Args: pretrained (str): Pretrained model name or path. c...
from typing import Optional import torch.nn as nn from transformers.models.gpt2.configuration_gpt2 import GPT2Config from transformers.models.gpt2.modeling_gpt2 import GPT2Model from .critic import Critic class GPTCritic(Critic): """ GPT Critic model. Args: pretrained (str): Pretrained model na...
from .reward_dataset import RewardDataset __all__ = ['RewardDataset']
from typing import Callable from torch.utils.data import Dataset from tqdm import tqdm class RewardDataset(Dataset): """ Dataset for reward model Args: dataset: dataset for reward model tokenizer: tokenizer for reward model max_length: max length of input """ def __init_...
from .base import Experience, ExperienceMaker from .naive import NaiveExperienceMaker __all__ = ['Experience', 'ExperienceMaker', 'NaiveExperienceMaker']
import torch from chatgpt.nn.utils import compute_reward, normalize from .base import Experience, ExperienceMaker class NaiveExperienceMaker(ExperienceMaker): """ Naive experience maker. """ @torch.no_grad() def make_experience(self, input_ids: torch.Tensor, **generate_kwargs) -> Experience: ...
from abc import ABC, abstractmethod from dataclasses import dataclass from typing import Optional import torch import torch.nn as nn from chatgpt.nn.actor import Actor @dataclass class Experience: """Experience is a batch of data. These data should have the the sequence length and number of actions. Left...
from .base import Trainer from .ppo import PPOTrainer from .rm import RewardModelTrainer __all__ = ['Trainer', 'PPOTrainer', 'RewardModelTrainer']
from abc import ABC import loralib as lora from chatgpt.dataset import RewardDataset from chatgpt.nn import PairWiseLoss from torch.optim import Adam, Optimizer from torch.utils.data import DataLoader from tqdm import tqdm from .strategies import Strategy from .utils import is_rank_0 class RewardModelTrainer(ABC): ...
import torch.distributed as dist def is_rank_0() -> bool: return not dist.is_initialized() or dist.get_rank() == 0
from typing import Any, Callable, Dict, List, Optional import torch.nn as nn from chatgpt.experience_maker import Experience, NaiveExperienceMaker from chatgpt.nn import Actor, Critic, PolicyLoss, ValueLoss from chatgpt.nn.generation_utils import update_model_kwargs_fn from chatgpt.replay_buffer import NaiveReplayBuff...
import random from abc import ABC, abstractmethod from typing import Any, Callable, Dict, List, Optional, Union import torch from chatgpt.experience_maker import Experience, ExperienceMaker from chatgpt.replay_buffer import ReplayBuffer from torch import Tensor from torch.utils.data import DistributedSampler from tqdm...
from .base import Callback from .performance_evaluator import PerformanceEvaluator __all__ = ['Callback', 'PerformanceEvaluator']
from time import time from typing import Optional import torch import torch.distributed as dist from chatgpt.experience_maker import Experience from .base import Callback def get_world_size() -> int: if dist.is_initialized(): return dist.get_world_size() return 1 def print_rank_0(*args, **kwargs) ...
from abc import ABC from chatgpt.experience_maker import Experience class Callback(ABC): """ Base callback class. It defines the interface for callbacks. """ def on_fit_start(self) -> None: pass def on_fit_end(self) -> None: pass def on_episode_start(self, episode: int)...
import os import random import numpy as np import torch import torch.distributed as dist import torch.nn as nn from chatgpt.replay_buffer import ReplayBuffer from torch.nn.parallel import DistributedDataParallel as DDP from torch.utils.data import DataLoader, DistributedSampler from .naive import NaiveStrategy clas...
from .base import Strategy from .colossalai import ColossalAIStrategy from .ddp import DDPStrategy from .naive import NaiveStrategy __all__ = ['Strategy', 'NaiveStrategy', 'DDPStrategy', 'ColossalAIStrategy']
import warnings from typing import Optional import torch import torch.distributed as dist import torch.nn as nn import torch.optim as optim import colossalai from colossalai.nn.optimizer import CPUAdam, HybridAdam from colossalai.nn.parallel import zero_model_wrapper, zero_optim_wrapper from colossalai.tensor import ...
import torch import torch.nn as nn import torch.optim as optim from chatgpt.replay_buffer import ReplayBuffer from torch.utils.data import DataLoader from .base import Strategy class NaiveStrategy(Strategy): """ Strategy for single GPU. No parallelism is used. """ def backward(self, loss: torch....
from abc import ABC, abstractmethod from contextlib import nullcontext import torch import torch.nn as nn import torch.optim as optim from chatgpt.replay_buffer import ReplayBuffer from torch.utils.data import DataLoader class Strategy(ABC): """ Base class for training strategies. """ def __init...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # import enum import os.path import shutil import functools import operator import collections from library import * ################################################################################################### # # Data structure model...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # import re ################################################################################################### import enum # The following block implements enum.auto() for Python 3.5 variants that don't include it such # as the default 3.5...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # import enum import os.path import shutil from library import * from gemm_operation import * from rank_k_operation import * from rank_2k_operation import * from trmm_operation import * from symm_operation import * from conv2d_operation impor...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # # import enum import os.path import shutil import functools import operator from library import * ################################################################################################### # # Data structure modeling a Rank K up...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # # import enum import os.path import shutil from library import * ################################################################################################### # class Conv2dOperation: # def __init__(self, conv_kind, iterator_alg...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # import enum import os.path import shutil import argparse import logging from library import * from manifest import * from itertools import product ############################################################################################...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # # import enum import os.path import shutil from library import * ################################################################################################### # class Conv3dOperation: # def __init__(self, conv_kind, iterator_alg...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # # import enum import os.path import shutil import functools import operator from library import * ################################################################################################### # # Data structure modeling a Rank K up...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # # import enum import os.path import shutil import functools import operator from library import * ################################################################################################### # # Data structure modeling a Symm upda...
# # \file generator.py # # \brief Generates the CUTLASS Library's instances # # import enum import os.path import shutil import functools import operator from library import * ################################################################################################### # # Data structure modeling a TRMM oper...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that ...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that ...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that ...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that t...
import re def SubstituteTemplate(template, values): text = template changed = True while changed: changed = False for key, value in values.items(): regex = "\\$\\{%s\\}" % key newtext = re.sub(regex, value, text) if newtext != text: chang...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that t...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that ...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that t...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that ...
################################################################################ # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that t...
################################################################################################# # # Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # # Redistribution and use in source and binary forms, with or without # modification, are permitt...