repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
bonito
bonito-master/bonito/reader.py
""" Bonito Read Utils """ from glob import iglob from collections import OrderedDict from importlib import import_module import torch import numpy as np from scipy.signal import find_peaks __formats__ = ["fast5", "pod5"] # Normalisation parameters for kit 14 DNA # Different parameters can be specified in the 'norm...
4,550
29.543624
109
py
bonito
bonito-master/bonito/training.py
""" Bonito train """ import math import os import re from glob import glob from functools import partial from time import perf_counter from collections import OrderedDict from datetime import datetime from bonito.schedule import linear_warmup_cosine_decay from bonito.util import accuracy, decode_ref, permute, concat,...
10,481
38.258427
129
py
bonito
bonito-master/bonito/data.py
import importlib import os from pathlib import Path import numpy as np from torch.utils.data import DataLoader class ChunkDataSet: def __init__(self, chunks, targets, lengths): self.chunks = np.expand_dims(chunks, axis=1) self.targets = targets self.lengths = lengths def __getitem__(...
2,868
32.752941
86
py
bonito
bonito-master/bonito/nn.py
""" Bonito nn modules. """ import torch from torch.nn import Module from torch.nn.init import orthogonal_ from torch.nn.utils.fusion import fuse_conv_bn_eval layers = {} def register(layer): layer.name = layer.__name__.lower() layers[layer.name] = layer return layer register(torch.nn.ReLU) register(t...
11,194
30.713881
133
py
bonito
bonito-master/bonito/util.py
""" Bonito utils """ import os import re import sys import random from glob import glob from itertools import groupby from operator import itemgetter from importlib import import_module from collections import deque, defaultdict, OrderedDict from torch.utils.data import DataLoader import toml import torch import koi....
13,291
30.49763
134
py
bonito
bonito-master/bonito/schedule.py
import math import numpy as np from torch.optim.lr_scheduler import LambdaLR def linear_warmup_cosine_decay(end_ratio=0.01, warmup_steps=500, **kwargs): """ Linear warmup, cosine decay scheduler """ return lambda optimizer, train_loader, epochs, last_epoch: func_scheduler( optimizer=optimizer...
3,330
26.528926
100
py
bonito
bonito-master/bonito/ctc/basecall.py
""" Bonito basecall """ import torch import numpy as np from functools import partial from bonito.multiprocessing import process_map from bonito.util import mean_qscore_from_qstring from bonito.util import chunk, stitch, batchify, unbatchify, permute def basecall(model, reads, beamsize=5, chunksize=0, overlap=0, ba...
2,018
31.564516
111
py
bonito
bonito-master/bonito/ctc/model.py
""" Bonito Model template """ import numpy as np from bonito.nn import Permute, layers import torch from torch.nn.functional import log_softmax, ctc_loss from torch.nn import Module, ModuleList, Sequential, Conv1d, BatchNorm1d, Dropout from fast_ctc_decode import beam_search, viterbi_search class Model(Module): ...
7,110
33.1875
155
py
bonito
bonito-master/bonito/cli/export.py
""" Bonito Export """ import io import os import re import sys import json import toml import torch import bonito import hashlib import numpy as np from glob import glob import base64 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from bonito.nn import fuse_bn_ from bonito.util import _load_model...
6,898
35.696809
150
py
bonito
bonito-master/bonito/cli/evaluate.py
""" Bonito model evaluator """ import os import time import torch import numpy as np from itertools import starmap from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from pathlib import Path from bonito.data import load_numpy, load_script from bonito.util import accuracy, poa, decode_ref, half_support...
3,647
31.283186
102
py
bonito
bonito-master/bonito/cli/train.py
#!/usr/bin/env python3 """ Bonito training. """ import os from argparse import ArgumentParser from argparse import ArgumentDefaultsHelpFormatter from pathlib import Path from importlib import import_module from bonito.data import load_numpy, load_script from bonito.util import __models__, default_config, default_dat...
4,704
35.472868
91
py
bonito
bonito-master/bonito/crf/basecall.py
""" Bonito CRF basecalling """ import torch import numpy as np from koi.decode import beam_search, to_str from bonito.multiprocessing import thread_iter from bonito.util import chunk, stitch, batchify, unbatchify, half_supported def stitch_results(results, length, size, overlap, stride, reverse=False): """ ...
2,632
30.345238
119
py
bonito
bonito-master/bonito/crf/model.py
""" Bonito CTC-CRF Model. """ import torch import numpy as np import koi from koi.ctc import SequenceDist, Max, Log, semiring from koi.ctc import logZ_cu, viterbi_alignments, logZ_cu_sparse, bwd_scores_cu_sparse, fwd_scores_cu_sparse from bonito.nn import Module, Convolution, LinearCRFEncoder, Serial, Permute, layer...
8,951
40.831776
191
py
ReAgent
ReAgent-master/reagent/ope/utils.py
#!/usr/bin/env python3 import math from collections import OrderedDict from typing import Sequence, Union import numpy as np import torch DEFAULT_MIN = float("-inf") DEFAULT_MAX = float("inf") def convert_to_one_hots(a, num_classes: int, dtype=torch.int, device=None): """ Convert class index array (num_sa...
2,743
26.717172
88
py
ReAgent
ReAgent-master/reagent/ope/estimators/slate_estimators.py
#!/usr/bin/env python3 import logging import math import random import time from abc import ABC, abstractmethod from dataclasses import dataclass from typing import ( Iterable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Set, Tuple, Union, ) import numpy as np imp...
54,387
34.225389
90
py
ReAgent
ReAgent-master/reagent/ope/estimators/sequential_estimators.py
#!/usr/bin/env python3 import copy import logging import random import time import typing from abc import ABC, abstractmethod from copy import deepcopy from dataclasses import dataclass from enum import Enum from functools import reduce from itertools import count, zip_longest from typing import Callable, Dict, Iterab...
28,267
34.964377
103
py
ReAgent
ReAgent-master/reagent/ope/estimators/types.py
#!/usr/bin/env python3 import logging import pickle from abc import ABC, abstractmethod from copy import deepcopy from dataclasses import dataclass from typing import Generic, Mapping, Optional, Sequence, Tuple, TypeVar, Union import numpy as np import torch from torch import Tensor def is_array(obj): return is...
18,646
30.712585
88
py
ReAgent
ReAgent-master/reagent/ope/estimators/contextual_bandits_estimators.py
#!/usr/bin/env python3 import logging import time from abc import ABC, abstractmethod from dataclasses import dataclass from typing import Optional, Sequence, Tuple, Union import numpy as np import torch from reagent.ope.estimators.estimator import Estimator, EstimatorResult from reagent.ope.estimators.types import (...
23,956
34.971471
117
py
ReAgent
ReAgent-master/reagent/ope/estimators/estimator.py
#!/usr/bin/env python3 import logging import math import pickle import tempfile from abc import ABC, abstractmethod from dataclasses import dataclass, field from multiprocessing import Pool from typing import Iterable, List, Mapping, Optional, Tuple, Union import torch from reagent.evaluation.cpe import bootstrapped_...
9,051
30.430556
92
py
ReAgent
ReAgent-master/reagent/ope/test/mslr_slate.py
#!/usr/bin/env python3 import argparse import itertools import json import logging import os import pickle import random import sys import time from collections import OrderedDict from typing import Iterable, List, Optional, Tuple import numpy as np import torch import torch.multiprocessing as mp from reagent.ope.est...
20,558
32.648118
111
py
ReAgent
ReAgent-master/reagent/ope/test/cartpole.py
#!/usr/bin/env python3 import logging import gym import torch from reagent.ope.estimators.sequential_estimators import ( Action, ActionDistribution, ActionSpace, IPSEstimator, Model, NeuralDualDICE, RandomRLPolicy, RewardProbability, RLEstimatorInput, RLPolicy, State, St...
8,083
31.079365
124
py
ReAgent
ReAgent-master/reagent/ope/test/gridworld.py
#!/usr/bin/env python3 import logging import random from typing import Iterable, Optional, Sequence, Tuple import numpy as np import torch from reagent.ope.estimators.sequential_estimators import ( DMEstimator, DoublyRobustEstimator, EpsilonGreedyRLPolicy, IPSEstimator, MAGICEstimator, NeuralD...
13,049
30.90709
88
py
ReAgent
ReAgent-master/reagent/ope/test/multiclass_bandits.py
#!/usr/bin/env python3 import argparse import json import logging import os import random import sys from dataclasses import dataclass from pathlib import PurePath from typing import Iterable, Tuple import numpy as np import pandas as pd import torch from reagent.ope.estimators.contextual_bandits_estimators import ( ...
11,560
33.927492
88
py
ReAgent
ReAgent-master/reagent/ope/test/yandex_web_search.py
#!/usr/bin/env python3 import argparse import json import logging import os import pickle import random import sys import time from typing import ( Dict, Iterable, List, Mapping, MutableMapping, Optional, Sequence, Tuple, Union, ) import numpy as np import torch import torch.multip...
25,761
35.855508
90
py
ReAgent
ReAgent-master/reagent/ope/test/unit_tests/test_slate_estimators.py
#!/usr/bin/env python3 import random import unittest import torch from reagent.ope.estimators.slate_estimators import ( DCGSlateMetric, NDCGSlateMetric, Slate, SlateItem, SlateItemProbabilities, SlateItemValues, SlateSlotItemProbabilities, SlateSlots, ) class TestEstimator(unittest.T...
2,939
38.72973
79
py
ReAgent
ReAgent-master/reagent/ope/test/unit_tests/test_types.py
#!/usr/bin/env python3 import unittest from typing import Tuple, Union import numpy as np import torch from reagent.ope.estimators.types import ( ActionDistribution as Distribution, TypeWrapper, Values, ) class TestTypes(unittest.TestCase): TestType = Union[int, Tuple[int], float, Tuple[float], np.n...
13,486
38.667647
86
py
ReAgent
ReAgent-master/reagent/ope/test/unit_tests/test_contextual_bandit_estimators.py
#!/usr/bin/env python3 import random import unittest import numpy as np import torch from reagent.ope.estimators.contextual_bandits_estimators import ( Action, ActionDistribution, ActionSpace, BanditsEstimatorInput, DMEstimator, DoublyRobustEstimator, IPSEstimator, LogSample, Model...
3,772
34.933333
85
py
ReAgent
ReAgent-master/reagent/ope/test/unit_tests/test_utils.py
#!/usr/bin/env python3 import unittest import numpy as np import torch from reagent.ope.utils import Clamper, RunningAverage class TestUtils(unittest.TestCase): def test_running_average(self): ra = RunningAverage() ra.add(1.0).add(2.0).add(3.0).add(4.0) self.assertEqual(ra.count, 4) ...
1,326
30.595238
87
py
ReAgent
ReAgent-master/reagent/ope/datasets/logged_dataset.py
#!/usr/bin/env python3 from abc import ABC, abstractmethod from dataclasses import dataclass import torch class BanditsDataset(ABC): """ Base class for logged, aka behavior, dataset """ @abstractmethod def __len__(self) -> int: """ Returns: length of the dataset ...
1,441
17.727273
56
py
ReAgent
ReAgent-master/reagent/ope/trainers/linear_trainers.py
#!/usr/bin/env python3 import logging import math import time from typing import Optional import numpy as np import torch from reagent.ope.estimators.types import PredictResults, Trainer, TrainingData from sklearn.linear_model import Lasso, LogisticRegression, SGDClassifier from sklearn.metrics import accuracy_score,...
12,799
35.571429
85
py
ReAgent
ReAgent-master/reagent/ope/trainers/rl_tabular_trainers.py
#!/usr/bin/env python3 import pickle from functools import reduce from typing import List, Mapping, Sequence import torch from reagent.ope.estimators.sequential_estimators import ( Model, RLPolicy, State, ValueFunction, ) from reagent.ope.estimators.types import Action, ActionDistribution, ActionSpace...
13,359
34.157895
88
py
ReAgent
ReAgent-master/reagent/mab/ucb.py
import math from abc import ABC, abstractmethod from typing import Union, Optional, List import torch from torch import Tensor def _get_arm_indices( ids_of_all_arms: List[Union[str, int]], ids_of_arms_in_batch: List[Union[str, int]] ) -> List[int]: arm_idxs = [] for i in ids_of_arms_in_batch: try...
12,188
34.85
143
py
ReAgent
ReAgent-master/reagent/gym/utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import random from typing import Dict, List, Optional import gym import numpy as np import pandas as pd import torch # @manual import torch.nn.functional as F from gym import spaces from reagent.core.paramet...
15,498
36.167866
88
py
ReAgent
ReAgent-master/reagent/gym/types.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # Please DO NOT import gym in here. We might have installation without gym depending on # this module for typing from abc import ABC, abstractmethod from dataclasses import asdict, dataclass, field, fields from typing impor...
4,633
30.52381
88
py
ReAgent
ReAgent-master/reagent/gym/preprocessors/default_preprocessors.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ Get default preprocessors for training time. """ import logging from typing import List, Optional, Tuple import numpy as np import reagent.core.types as rlt import torch import torch.nn.functional as F from gym import ...
4,247
32.714286
88
py
ReAgent
ReAgent-master/reagent/gym/preprocessors/trainer_preprocessor.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ Get default preprocessors for training time. """ import inspect import logging from typing import Dict, Optional import gym import numpy as np import reagent.core.types as rlt import torch import torch.nn.functional as...
18,178
36.637681
88
py
ReAgent
ReAgent-master/reagent/gym/envs/oracle_pvm.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from collections import OrderedDict from typing import Callable, Dict, List import gym import numpy as np import reagent.core.types as rlt import torch from reagent.core.dataclasses import dataclass from reag...
6,305
35.034286
100
py
ReAgent
ReAgent-master/reagent/gym/envs/changing_arms.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ Traditional MAB setup has sequence length = 1 always. In this setup, the distributions of the arms rewards changes every round, and the agent is presented with some information and control about how the arms will change....
10,024
34.9319
86
py
ReAgent
ReAgent-master/reagent/gym/envs/gym.py
#!/usr/bin/env python3 import logging from typing import Optional, Tuple import gym import numpy as np import reagent.core.types as rlt import torch from gym import spaces from gym_minigrid.wrappers import ReseedWrapper from reagent.core.dataclasses import dataclass from reagent.gym.envs.env_wrapper import EnvWrapper...
1,987
33.275862
86
py
ReAgent
ReAgent-master/reagent/gym/envs/env_wrapper.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import abc import logging from typing import Callable, Optional import gym import numpy as np import reagent.core.types as rlt import torch from gym import spaces from reagent.core.dataclasses import dataclass from reagent....
5,302
35.572414
88
py
ReAgent
ReAgent-master/reagent/gym/envs/pomdp/string_game_v1.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ A game with a stochastic length of the MDP but no longer than 3. An agent can choose one character to reveal (either "A" or "B") as the action, and the next state is exactly the action just taken (i.e., the transition fu...
4,664
33.051095
91
py
ReAgent
ReAgent-master/reagent/gym/envs/pomdp/state_embed_env.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ This file shows an example of using embedded states to feed to RL models in partially observable environments (POMDPs). Embedded states are generated by a world model which learns how to encode past n observations into a ...
4,927
38.424
86
py
ReAgent
ReAgent-master/reagent/gym/envs/pomdp/string_game.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ The agent can observe a character at one time. But the reward is given based on last n (n>1) steps' observation (a string). In this environment, the agent can observe a character ("A", "B") at each time step, but the rewa...
4,391
31.533333
80
py
ReAgent
ReAgent-master/reagent/gym/policies/predictor_policies.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import Optional, Tuple, Union import numpy as np import reagent.core.types as rlt import torch from reagent.core.fb_checker import IS_FB_ENVIRONMENT from reagent.core.parameters import RLParameters from reagent....
5,542
38.592857
86
py
ReAgent
ReAgent-master/reagent/gym/policies/policy.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import Any, Optional import reagent.core.types as rlt import torch from reagent.gym.types import Sampler, Scorer class Policy: def __init__(self, scorer: Scorer, sampler: Sampler): """ The ...
1,245
31.789474
77
py
ReAgent
ReAgent-master/reagent/gym/policies/random_policies.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import List, Optional import gym import numpy as np import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.parameters import CONTINUOUS_TRAINING_ACTION_RANGE from reagent...
5,717
38.434483
88
py
ReAgent
ReAgent-master/reagent/gym/policies/scorers/slate_q_scorer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.gym.types import Scorer from reagent.models.base import ModelBase def slate_q_scorer(num_candidates: int, q_network: ModelBase) -> ...
1,838
31.839286
86
py
ReAgent
ReAgent-master/reagent/gym/policies/scorers/continuous_scorer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import reagent.core.types as rlt import torch from reagent.gym.types import GaussianSamplerScore, Scorer from reagent.models.base import ModelBase def sac_scorer(actor_network: ModelBase) -> Scorer: @torch.no_grad() ...
699
34
83
py
ReAgent
ReAgent-master/reagent/gym/policies/scorers/discrete_scorer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import Optional, Tuple import numpy as np import reagent.core.types as rlt import torch from reagent.gym.preprocessors.trainer_preprocessor import get_possible_actions_for_gym from reagent.gym.types import Score...
3,740
32.106195
87
py
ReAgent
ReAgent-master/reagent/gym/policies/samplers/continuous_sampler.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import reagent.core.types as rlt import torch from reagent.gym.types import GaussianSamplerScore, Sampler class GaussianSampler(Sampler): def __init__(self, actor_network): self.actor_network = actor_network ...
2,378
41.482143
87
py
ReAgent
ReAgent-master/reagent/gym/policies/samplers/top_k_sampler.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import reagent.core.types as rlt import torch from reagent.gym.types import Sampler class TopKSampler(Sampler): def __init__(self, k: int): self.k = k def sample_action(self, scores: torch.Tensor) -> rlt....
634
27.863636
83
py
ReAgent
ReAgent-master/reagent/gym/policies/samplers/discrete_sampler.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.gym.types import Sampler from reagent.models.dqn import INVALID_ACTION_CONSTANT class SoftmaxActionSampler(Sampler): """ S...
7,223
37.425532
101
py
ReAgent
ReAgent-master/reagent/gym/datasets/replay_buffer_dataset.py
#!/usr/bin/env python3 import logging from typing import Optional, Callable import torch from reagent.gym.agents.agent import Agent from reagent.gym.envs import EnvWrapper from reagent.gym.preprocessors import ( make_replay_buffer_inserter, make_replay_buffer_trainer_preprocessor, ) from reagent.gym.types imp...
6,916
33.242574
90
py
ReAgent
ReAgent-master/reagent/gym/datasets/episodic_dataset.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import Optional import torch from reagent.gym.agents.agent import Agent from reagent.gym.envs.gym import Gym from reagent.gym.runners.gymrunner import run_episode logger = logging.getLogger(__na...
1,020
23.902439
72
py
ReAgent
ReAgent-master/reagent/gym/agents/agent.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import Any, Optional, Tuple, Union import numpy as np import torch from reagent.gym.envs.env_wrapper import EnvWrapper from reagent.gym.policies.policy import Policy from reagent.gym.policies.random_policies imp...
4,248
31.435115
79
py
ReAgent
ReAgent-master/reagent/gym/tests/test_gym_offline.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import os import pprint import unittest import uuid import numpy as np import pytest import pytorch_lightning as pl import torch from parameterized import parameterized from reagent.gym.agents.agent import Age...
4,868
30.412903
83
py
ReAgent
ReAgent-master/reagent/gym/tests/test_gym.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import os import pprint import unittest import uuid from typing import Optional import numpy as np import pytest import pytorch_lightning as pl import torch from parameterized import parameterized from reagent...
11,439
33.251497
112
py
ReAgent
ReAgent-master/reagent/gym/tests/test_world_model.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import os import unittest from typing import Dict, List, Optional import gym import numpy as np import reagent.core.types as rlt import torch from reagent.evaluation.world_model_evaluator import ( FeatureI...
15,345
35.451306
88
py
ReAgent
ReAgent-master/reagent/gym/tests/preprocessors/test_default_preprocessors.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import unittest import gym import numpy.testing as npt import torch import torch.nn.functional as F from reagent.gym.envs import Gym try: from reagent.gym.envs import RecSim HAS_RECSIM = True except ModuleNotFoun...
4,748
40.657895
85
py
ReAgent
ReAgent-master/reagent/gym/tests/preprocessors/test_replay_buffer_inserters.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import unittest import gym import numpy as np import numpy.testing as npt import torch from reagent.gym.envs import EnvWrapper from reagent.gym.preprocessors import make_replay_buffer_inserter from reagent.gy...
6,822
38.668605
85
py
ReAgent
ReAgent-master/reagent/gym/runners/gymrunner.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import pickle from typing import Optional, Sequence import numpy as np import torch.multiprocessing as mp from reagent.core.multiprocess_utils import ( unwrap_function_outputs, wrap_function_arguments...
4,541
32.397059
87
py
ReAgent
ReAgent-master/reagent/evaluation/evaluation_data_page.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from __future__ import annotations import logging import math from dataclasses import dataclass, fields from typing import TYPE_CHECKING, Optional, cast import numpy as np import torch import torch.nn as nn from reagent.co...
26,496
40.401563
96
py
ReAgent
ReAgent-master/reagent/evaluation/world_model_evaluator.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import Dict, List import torch from reagent.core.types import FeatureData, MemoryNetworkInput from reagent.training.world_model.mdnrnn_trainer import MDNRNNTrainer logger = logging.getLogger(__na...
9,841
39.336066
88
py
ReAgent
ReAgent-master/reagent/evaluation/sequential_doubly_robust_estimator.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import List import numpy as np import torch from reagent.evaluation.cpe import CpeEstimate, bootstrapped_std_error_of_mean from reagent.evaluation.evaluation_data_page import EvaluationDataPage ...
5,254
36.535714
88
py
ReAgent
ReAgent-master/reagent/evaluation/doubly_robust_estimator.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import itertools import logging from dataclasses import dataclass from typing import Dict, NamedTuple, Optional, Tuple, Union import numpy as np import torch from reagent.evaluation.cpe import CpeEstimate, bootstrapped_std_...
13,063
37.997015
88
py
ReAgent
ReAgent-master/reagent/evaluation/evaluator.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from collections import Counter from typing import Dict, List, Optional import torch import torch.nn.functional as F from reagent.core.tracker import observable from reagent.evaluation.cpe import CpeDetails, ...
6,718
35.516304
89
py
ReAgent
ReAgent-master/reagent/evaluation/cpe.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import math from typing import Dict, NamedTuple, Optional import numpy as np import torch from reagent.core.tensorboardX import SummaryWriterContext logger = logging.getLogger(__name__) class CpeEstimate(...
6,820
34.9
114
py
ReAgent
ReAgent-master/reagent/evaluation/weighted_sequential_doubly_robust_estimator.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import itertools import logging import numpy as np import scipy as sp import torch from reagent.evaluation.cpe import CpeEstimate from reagent.evaluation.evaluation_data_page import EvaluationDataPage logger = logging.get...
14,541
36.576227
106
py
ReAgent
ReAgent-master/reagent/evaluation/ope_adapter.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import torch from reagent.evaluation.cpe import ( CpeEstimate, CpeEstimateSet, bootstrapped_std_error_of_mean, ) from reagent.evaluation.evaluation_data_page import EvaluationDataPage from reagent...
10,869
36.353952
96
py
ReAgent
ReAgent-master/reagent/evaluation/feature_importance/feature_importance_perturbation.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import copy import logging from collections import defaultdict from typing import Callable, Any, Optional import pandas as pd import torch import torch.nn as nn from reagent.core.dataclasses import dataclass from reagent.eva...
2,857
37.106667
87
py
ReAgent
ReAgent-master/reagent/evaluation/feature_importance/feature_importance_base.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import List import pandas as pd import torch.nn as nn from reagent.core.dataclasses import dataclass @dataclass class FeatureImportanceBase: model: nn.Module sorted_feature_ids: List[int] def compu...
401
22.647059
71
py
ReAgent
ReAgent-master/reagent/core/aggregators.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from collections import deque from typing import Callable, Deque, Dict, List, Optional, Any import numpy as np import torch from reagent.core.tensorboardX import SummaryWriterContext from reagent.core.tracker...
7,651
30.751037
87
py
ReAgent
ReAgent-master/reagent/core/tracker.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import functools import logging from typing import Dict, List, Type import torch logger = logging.getLogger(__name__) class Observer: """ Base class for observers """ def __init__(self, observing_keys: ...
3,958
28.110294
80
py
ReAgent
ReAgent-master/reagent/core/utils.py
#!/usr/bin/env python3 from typing import Tuple, Optional import torch def get_rank() -> int: """ Returns the torch.distributed rank of the process. 0 represents the main process and is the default if torch.distributed isn't set up """ return ( torch.distributed.get_rank() if tor...
975
24.684211
82
py
ReAgent
ReAgent-master/reagent/core/configuration.py
#!/usr/bin/python3 import functools from dataclasses import MISSING, Field, fields from inspect import Parameter, isclass, signature from typing import List, Optional, Type, Union from reagent.core.dataclasses import dataclass from torch import nn BLOCKLIST_TYPES = [nn.Module] def _get_param_annotation(p): # ...
5,364
31.515152
88
py
ReAgent
ReAgent-master/reagent/core/types.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import dataclasses import logging # The dataclasses in this file should be vanilla dataclass to have minimal overhead from dataclasses import dataclass, field from typing import Dict, List, NamedTuple, Optional, Tuple, Unio...
37,736
34.136872
91
py
ReAgent
ReAgent-master/reagent/core/torch_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from io import BytesIO from typing import Dict import numpy as np import torch def dict_to_tensor(batch: Dict[str, np.ndarray], device: str = "cpu"): return {k: torch.tensor(v).to(device) for k, v in batch.items()} d...
3,085
29.86
93
py
ReAgent
ReAgent-master/reagent/core/parameters.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import enum from typing import Dict, List, Optional from reagent.core.base_dataclass import BaseDataClass from reagent.core.configuration import param_hash from reagent.core.dataclasses import dataclass, field from reagent....
6,022
26.884259
80
py
ReAgent
ReAgent-master/reagent/core/oss_tensorboard_logger.py
from typing import Optional, Union, Dict, List, Tuple import torch from pytorch_lightning.loggers import TensorBoardLogger from pytorch_lightning.utilities import rank_zero_only class LocalCacheLogger: @staticmethod def store_metrics( tb_logger, metrics: Dict[ str, Union[float, to...
4,531
33.861538
136
py
ReAgent
ReAgent-master/reagent/core/tensorboardX.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ Context library to allow dropping tensorboardX anywhere in the codebase. If there is no SummaryWriter in the context, function calls will be no-op. Usage: writer = SummaryWriter() with summary_writer_context(w...
3,412
26.97541
83
py
ReAgent
ReAgent-master/reagent/training/cem_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. """ The Trainer for Cross-Entropy Method. The idea is that an ensemble of world models are fitted to predict transitions and reward functions. A cross entropy method-based planner will then plan the best next action based on...
1,805
35.12
87
py
ReAgent
ReAgent-master/reagent/training/qrdqn_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import List, Tuple import reagent.core.types as rlt import torch from reagent.core.configuration import resolve_defaults from reagent.core.dataclasses import field from reagent.core.parameters imp...
8,782
36.216102
94
py
ReAgent
ReAgent-master/reagent/training/reinforce_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import inspect import logging import math from dataclasses import field from typing import List, Optional import reagent.core.types as rlt import torch import torch.optim from reagent.gym.policies.policy import Policy from r...
4,640
37.040984
87
py
ReAgent
ReAgent-master/reagent/training/parametric_dqn_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import Tuple import reagent.core.parameters as rlp import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.configuration import resolve_defaults from reagen...
7,284
39.027473
88
py
ReAgent
ReAgent-master/reagent/training/sac_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import copy import logging from typing import List, Optional import numpy as np import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.configuration import resolve_defaults from reage...
14,825
38.118734
94
py
ReAgent
ReAgent-master/reagent/training/utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import numpy as np import torch import torch.nn.functional as F EPS = np.finfo(float).eps.item() def rescale_actions( actions: torch.Tensor, new_min: torch.Tensor, new_max: torch.Tensor, prev_min: torch.T...
1,864
29.080645
80
py
ReAgent
ReAgent-master/reagent/training/reagent_lightning_module.py
#!/usr/bin/env python3 import inspect import logging import pytorch_lightning as pl import torch from reagent.core.tensorboardX import SummaryWriterContext from reagent.core.utils import lazy_property from typing_extensions import final logger = logging.getLogger(__name__) class ReAgentLightningModule(pl.Lightnin...
7,568
35.921951
128
py
ReAgent
ReAgent-master/reagent/training/c51_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. from typing import List import reagent.core.types as rlt import torch from reagent.core.configuration import resolve_defaults from reagent.core.dataclasses import field from reagent.core.parameters import RLParameters from ...
8,784
41.033493
101
py
ReAgent
ReAgent-master/reagent/training/multi_stage_trainer.py
#!/usr/bin/env python3 import bisect import functools import itertools from collections import OrderedDict from typing import List, Dict, Tuple import torch.nn as nn from pytorch_lightning.loops.optimization.optimizer_loop import ClosureResult from reagent.core.utils import lazy_property from .reagent_lightning_modu...
7,726
36.509709
116
py
ReAgent
ReAgent-master/reagent/training/ppo_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import inspect import logging from dataclasses import field from typing import Dict, List, Optional, Union import reagent.core.types as rlt import torch import torch.optim from reagent.core.configuration import resolve_defau...
8,551
38.410138
118
py
ReAgent
ReAgent-master/reagent/training/dqn_trainer_base.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import List, Optional import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.parameters import EvaluationParameters, RLParameters from reagent.core.torch_u...
14,123
39.469914
115
py
ReAgent
ReAgent-master/reagent/training/slate_q_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import enum import logging from typing import Optional import reagent.core.parameters as rlp import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.dataclasses import field from reag...
10,984
38.800725
117
py
ReAgent
ReAgent-master/reagent/training/imitator_training.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import torch logger = logging.getLogger(__name__) def get_valid_actions_from_imitator(imitator, input, drop_threshold): """Create mask for non-viable actions under the imitator.""" if isinstance(im...
804
31.2
85
py
ReAgent
ReAgent-master/reagent/training/reward_network_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from enum import Enum from typing import Optional import numpy as np import reagent.core.types as rlt import torch from reagent.core.dataclasses import field from reagent.models.base import ModelBase from reag...
6,165
34.034091
85
py
ReAgent
ReAgent-master/reagent/training/dqn_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import List, Optional, Tuple import reagent.core.types as rlt import torch from reagent.core.configuration import resolve_defaults from reagent.core.dataclasses import dataclass, field from reagen...
12,069
37.935484
96
py
ReAgent
ReAgent-master/reagent/training/td3_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import copy import logging import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.configuration import resolve_defaults from reagent.core.dataclasses import field from reagent.core.pa...
7,751
38.350254
100
py
ReAgent
ReAgent-master/reagent/training/discrete_crr_trainer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. # Note: this files is modeled after td3_trainer.py import logging from typing import List, Tuple import reagent.core.types as rlt import torch import torch.nn.functional as F from reagent.core.configuration import resolve_...
18,427
41.266055
94
py
ReAgent
ReAgent-master/reagent/training/gradient_free/es_worker.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging import torch import torch.distributed as distributed import torch.nn import torch.optim from reagent.core.parameters import EvolutionParameters from reagent.training.gradient_free.evolution_pool import Evolut...
1,861
30.033333
77
py
ReAgent
ReAgent-master/reagent/training/gradient_free/ars_util.py
from operator import itemgetter import numpy as np import torch """ Utility functions for Advanced Random Search (ARS) algorithm based on the paper "Simple random search provides a competitive approach to reinforcement learning", Mania et al. https://arxiv.org/abs/1803.07055 Here, we show an example of training a d...
4,380
34.909836
87
py
ReAgent
ReAgent-master/reagent/training/gradient_free/evolution_pool.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from typing import Dict, List import torch import torch.fb.rendezvous.zeus import torch.nn import torch.optim from reagent.core.parameters import EvolutionParameters logger = logging.getLogger(__name__) MA...
4,802
35.112782
86
py