id int64 0 328k | repository_name stringlengths 7 58 | file_path stringlengths 9 302 | class_name stringlengths 5 256 | human_written_code stringlengths 16 2.16M | class_skeleton stringlengths 18 1.49M ⌀ | total_program_units int64 1 1.76k | total_doc_str int64 0 771 | AvgCountLine float64 0 7.89k | AvgCountLineBlank float64 0 297 | AvgCountLineCode float64 0 7.89k | AvgCountLineComment float64 0 7.89k | AvgCyclomatic float64 0 130 | CommentToCodeRatio float64 0 168 | CountClassBase float64 0 40 | CountClassCoupled float64 0 583 | CountClassCoupledModified float64 0 575 | CountClassDerived float64 0 5.35k | CountDeclInstanceMethod float64 0 529 | CountDeclInstanceVariable float64 0 296 | CountDeclMethod float64 0 599 | CountDeclMethodAll float64 0 1.12k | CountLine float64 1 40.4k | CountLineBlank float64 0 8.16k | CountLineCode float64 1 25.7k | CountLineCodeDecl float64 1 8.15k | CountLineCodeExe float64 0 24.2k | CountLineComment float64 0 16.5k | CountStmt float64 1 9.71k | CountStmtDecl float64 1 8.15k | CountStmtExe float64 0 9.69k | MaxCyclomatic float64 0 759 | MaxInheritanceTree float64 0 16 | MaxNesting float64 0 34 | SumCyclomatic float64 0 2.9k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
11,500 | ray-project/ray | rllib/examples/learners/classes/intrinsic_curiosity_learners.py | rllib.examples.learners.classes.intrinsic_curiosity_learners.DQNTorchLearnerWithCuriosity | from ray.rllib.algorithms.dqn.torch.dqn_torch_learner import DQNTorchLearner
class DQNTorchLearnerWithCuriosity(DQNTorchLearner):
def build(self) -> None:
super().build()
add_intrinsic_curiosity_connectors(self) |
class DQNTorchLearnerWithCuriosity(DQNTorchLearner):
def build(self) -> None:
pass | 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 4 | 0 | 4 | 2 | 2 | 0 | 4 | 2 | 2 | 1 | 1 | 0 | 1 |
11,501 | ray-project/ray | rllib/examples/learners/classes/intrinsic_curiosity_learners.py | rllib.examples.learners.classes.intrinsic_curiosity_learners.IntrinsicCuriosityModelConnector | from ray.rllib.connectors.connector_v2 import ConnectorV2
from ray.rllib.core import Columns, DEFAULT_MODULE_ID
import torch
import gymnasium as gym
from typing import Any, List, Optional
from ray.rllib.core.rl_module.rl_module import RLModule
from ray.rllib.utils.typing import EpisodeType
class IntrinsicCuriosityMode... |
class IntrinsicCuriosityModelConnector(ConnectorV2):
'''Learner ConnectorV2 piece to compute intrinsic rewards based on an ICM.
For more details, see here:
[1] Curiosity-driven Exploration by Self-supervised Prediction
Pathak, Agrawal, Efros, and Darrell - UC Berkeley - ICML 2017.
https://arxiv.org... | 3 | 2 | 26 | 3 | 16 | 7 | 1 | 0.91 | 1 | 5 | 0 | 0 | 2 | 1 | 2 | 2 | 72 | 9 | 33 | 21 | 14 | 30 | 12 | 5 | 9 | 1 | 1 | 1 | 2 |
11,502 | ray-project/ray | rllib/examples/learners/classes/intrinsic_curiosity_learners.py | rllib.examples.learners.classes.intrinsic_curiosity_learners.PPOTorchLearnerWithCuriosity | from ray.rllib.algorithms.ppo.torch.ppo_torch_learner import PPOTorchLearner
class PPOTorchLearnerWithCuriosity(PPOTorchLearner):
def build(self) -> None:
super().build()
add_intrinsic_curiosity_connectors(self) |
class PPOTorchLearnerWithCuriosity(PPOTorchLearner):
def build(self) -> None:
pass | 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 4 | 0 | 4 | 2 | 2 | 0 | 4 | 2 | 2 | 1 | 1 | 0 | 1 |
11,503 | ray-project/ray | rllib/examples/learners/classes/separate_vf_lr_and_optimizer_learner.py | rllib.examples.learners.classes.separate_vf_lr_and_optimizer_learner.PPOTorchLearnerWithSeparateVfOptimizer | from ray.rllib.utils.annotations import override
from ray.rllib.utils.typing import ModuleID
from ray.rllib.algorithms.ppo.torch.ppo_torch_learner import PPOTorchLearner
from ray.rllib.core.learner.torch.torch_learner import TorchLearner
class PPOTorchLearnerWithSeparateVfOptimizer(PPOTorchLearner):
"""A custom PP... |
class PPOTorchLearnerWithSeparateVfOptimizer(PPOTorchLearner):
'''A custom PPO torch learner with 2 optimizers, for policy and value function.
Overrides the Learner's standard `configure_optimizers_for_module()` method to
register the additional vf optimizer.
The standard PPOLearner only uses a single ... | 3 | 2 | 55 | 3 | 36 | 16 | 1 | 0.74 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 73 | 7 | 38 | 10 | 31 | 28 | 9 | 5 | 7 | 1 | 1 | 0 | 1 |
11,504 | ray-project/ray | rllib/examples/learners/classes/vpg_torch_learner.py | rllib.examples.learners.classes.vpg_torch_learner.VPGTorchLearner | from ray.rllib.utils.annotations import override
from ray.rllib.utils.typing import ModuleID, TensorType
import numpy as np
from ray.rllib.utils.numpy import convert_to_numpy
from ray.rllib.connectors.learner import ComputeReturnsToGo
from ray.rllib.core.learner.learner import Learner
from ray.rllib.core.learner.torch.... |
class VPGTorchLearner(TorchLearner):
@override(TorchLearner)
def build(self) -> None:
pass
@override(TorchLearner)
def compute_loss_for_module(self, *, module_id: ModuleID, config: 'AlgorithmConfig', batch: Dict[str, Any], fwd_out: Dict[str, TensorType]) -> TensorType:
pass
@overri... | 7 | 0 | 17 | 2 | 11 | 3 | 2 | 0.26 | 1 | 4 | 0 | 0 | 3 | 0 | 3 | 3 | 56 | 8 | 38 | 24 | 24 | 10 | 21 | 14 | 17 | 3 | 1 | 2 | 7 |
11,505 | ray-project/ray | rllib/examples/learners/ppo_with_torch_lr_schedulers.py | rllib.examples.learners.ppo_with_torch_lr_schedulers.LRChecker | from ray.rllib.callbacks.callbacks import RLlibCallback
from ray.rllib.utils.metrics.metrics_logger import MetricsLogger
from ray.rllib.core.learner.learner import DEFAULT_OPTIMIZER
import numpy as np
from ray.rllib.core import DEFAULT_MODULE_ID
from typing import Optional
class LRChecker(RLlibCallback):
def on_a... |
class LRChecker(RLlibCallback):
def on_algorithm_init(self, *, algorithm: 'Algorithm', metrics_logger: Optional[MetricsLogger]=None, **kwargs) -> None:
pass
def on_train_result(self, *, algorithm: 'Algorithm', metrics_logger: Optional[MetricsLogger]=None, result: dict, **kwargs) -> None:
pass | 3 | 0 | 25 | 1 | 20 | 5 | 3 | 0.22 | 1 | 2 | 0 | 0 | 2 | 1 | 2 | 2 | 52 | 2 | 41 | 23 | 25 | 9 | 16 | 10 | 13 | 3 | 1 | 2 | 5 |
11,506 | ray-project/ray | rllib/examples/metrics/custom_metrics_in_algorithm_training_step.py | rllib.examples.metrics.custom_metrics_in_algorithm_training_step.MyVPGWithExtraMetrics | from ray.rllib.utils.metrics import ENV_RUNNER_SAMPLING_TIMER, LEARNER_UPDATE_TIMER, TIMERS
from ray.rllib.utils.annotations import override
from ray.rllib.examples.algorithms.classes.vpg import VPG, VPGConfig
from ray.rllib.algorithms import AlgorithmConfig
class MyVPGWithExtraMetrics(VPG):
@override(VPG)
de... |
class MyVPGWithExtraMetrics(VPG):
@override(VPG)
def training_step(self) -> None:
pass
@classmethod
@override(VPG)
def get_default_config(cls) -> AlgorithmConfig:
pass | 6 | 0 | 8 | 1 | 5 | 2 | 1 | 0.21 | 1 | 1 | 0 | 0 | 1 | 0 | 2 | 2 | 20 | 3 | 14 | 7 | 8 | 3 | 8 | 5 | 5 | 1 | 1 | 0 | 2 |
11,507 | ray-project/ray | rllib/examples/metrics/custom_metrics_in_env_runners.py | rllib.examples.metrics.custom_metrics_in_env_runners.MsPacmanHeatmapCallback | import gymnasium as gym
import matplotlib.pyplot as plt
from typing import Optional, Sequence
import numpy as np
from ray.rllib.utils.images import resize
from ray.rllib.callbacks.callbacks import RLlibCallback
from matplotlib.colors import Normalize
class MsPacmanHeatmapCallback(RLlibCallback):
"""A custom callba... |
class MsPacmanHeatmapCallback(RLlibCallback):
'''A custom callback to extract information from MsPacman and log these.
This callback logs:
- the positions of MsPacman over an episode to produce heatmaps from this data.
At each episode timestep, the current pacman (y/x)-position is determined and added
... | 7 | 3 | 35 | 3 | 23 | 10 | 2 | 0.53 | 1 | 2 | 0 | 0 | 5 | 2 | 5 | 5 | 196 | 21 | 118 | 54 | 82 | 62 | 49 | 24 | 43 | 4 | 1 | 2 | 12 |
11,508 | ray-project/ray | rllib/examples/multi_agent/different_spaces_for_agents.py | rllib.examples.multi_agent.different_spaces_for_agents.BasicMultiAgentMultiSpaces | import gymnasium as gym
from ray.rllib.env.multi_agent_env import MultiAgentEnv
class BasicMultiAgentMultiSpaces(MultiAgentEnv):
"""A simple multi-agent example environment where agents have different spaces.
agent0: obs=Box(10,), act=Discrete(2)
agent1: obs=Box(20,), act=Discrete(3)
The logic of the... |
class BasicMultiAgentMultiSpaces(MultiAgentEnv):
'''A simple multi-agent example environment where agents have different spaces.
agent0: obs=Box(10,), act=Discrete(2)
agent1: obs=Box(20,), act=Discrete(3)
The logic of the env doesn't really matter for this example. The point of this env
is to show ... | 4 | 1 | 11 | 1 | 9 | 1 | 1 | 0.31 | 1 | 2 | 0 | 0 | 3 | 5 | 3 | 3 | 46 | 8 | 29 | 11 | 25 | 9 | 23 | 11 | 19 | 2 | 1 | 1 | 4 |
11,509 | ray-project/ray | rllib/examples/multi_agent/utils/self_play_callback.py | rllib.examples.multi_agent.utils.self_play_callback.SelfPlayCallback | from ray.rllib.callbacks.callbacks import RLlibCallback
from ray.rllib.core.rl_module.rl_module import RLModuleSpec
from ray.rllib.utils.metrics import ENV_RUNNER_RESULTS
from collections import defaultdict
import numpy as np
class SelfPlayCallback(RLlibCallback):
def __init__(self, win_rate_threshold):
s... |
class SelfPlayCallback(RLlibCallback):
def __init__(self, win_rate_threshold):
pass
def on_episode_end(self, *, episode, env_runner, metrics_logger, env, env_index, rl_module, **kwargs) -> None:
pass
def on_train_result(self, *, algorithm, metrics_logger=None, result, **kwargs):
... | 5 | 0 | 24 | 2 | 18 | 5 | 2 | 0.25 | 1 | 4 | 0 | 0 | 3 | 3 | 3 | 3 | 87 | 8 | 63 | 25 | 48 | 16 | 31 | 15 | 26 | 3 | 1 | 1 | 8 |
11,510 | ray-project/ray | rllib/examples/multi_agent/utils/self_play_callback_old_api_stack.py | rllib.examples.multi_agent.utils.self_play_callback_old_api_stack.SelfPlayCallbackOldAPIStack | from ray.rllib.callbacks.callbacks import RLlibCallback
from ray.rllib.utils.metrics import ENV_RUNNER_RESULTS
from ray._common.deprecation import Deprecated
import numpy as np
@Deprecated(help='Use the example for the new RLlib API stack.', error=False)
class SelfPlayCallbackOldAPIStack(RLlibCallback):
def __ini... | @Deprecated(help='Use the example for the new RLlib API stack.', error=False)
class SelfPlayCallbackOldAPIStack(RLlibCallback):
def __init__(self, win_rate_threshold):
pass
def on_train_result(self, *, algorithm, result, **kwargs):
pass
def policy_mapping_fn(agent_id, episode, wor... | 5 | 0 | 26 | 2 | 17 | 8 | 2 | 0.49 | 1 | 5 | 0 | 0 | 2 | 2 | 2 | 2 | 70 | 6 | 43 | 15 | 39 | 21 | 29 | 15 | 25 | 4 | 1 | 2 | 7 |
11,511 | ray-project/ray | rllib/examples/multi_agent/utils/self_play_league_based_callback.py | rllib.examples.multi_agent.utils.self_play_league_based_callback.SelfPlayLeagueBasedCallback | from ray.rllib.callbacks.callbacks import RLlibCallback
import numpy as np
from pprint import pprint
import re
from ray.rllib.utils.metrics import ENV_RUNNER_RESULTS
from collections import defaultdict
from ray.rllib.core.rl_module.rl_module import RLModuleSpec
class SelfPlayLeagueBasedCallback(RLlibCallback):
de... |
class SelfPlayLeagueBasedCallback(RLlibCallback):
def __init__(self, win_rate_threshold):
pass
def on_episode_end(self, *, episode, env_runner, metrics_logger, env, env_index, rl_module, **kwargs) -> None:
pass
def on_train_result(self, *, algorithm, metrics_logger=None, result, **kwargs... | 6 | 0 | 61 | 5 | 44 | 13 | 5 | 0.29 | 1 | 5 | 0 | 0 | 4 | 8 | 4 | 4 | 264 | 22 | 189 | 49 | 173 | 54 | 100 | 39 | 94 | 11 | 1 | 4 | 26 |
11,512 | ray-project/ray | rllib/examples/multi_agent/utils/self_play_league_based_callback_old_api_stack.py | rllib.examples.multi_agent.utils.self_play_league_based_callback_old_api_stack.SelfPlayLeagueBasedCallbackOldAPIStack | import numpy as np
import re
from ray._common.deprecation import Deprecated
from ray.rllib.callbacks.callbacks import RLlibCallback
from ray.rllib.utils.metrics import ENV_RUNNER_RESULTS
@Deprecated(help='Use the example for the new RLlib API stack', error=False)
class SelfPlayLeagueBasedCallbackOldAPIStack(RLlibCallb... | @Deprecated(help='Use the example for the new RLlib API stack', error=False)
class SelfPlayLeagueBasedCallbackOldAPIStack(RLlibCallback):
def __init__(self, win_rate_threshold):
pass
def on_train_result(self, *, algorithm, result, **kwargs):
pass
def policy_mapping_fn(agent_id... | 7 | 0 | 47 | 4 | 34 | 10 | 5 | 0.26 | 1 | 5 | 0 | 0 | 3 | 7 | 3 | 3 | 191 | 18 | 138 | 34 | 132 | 36 | 88 | 34 | 82 | 13 | 1 | 4 | 26 |
11,513 | ray-project/ray | rllib/examples/offline_rl/classes/image_offline_data.py | rllib.examples.offline_rl.classes.image_offline_data.ImageOfflineData | from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
import numpy as np
from ray.rllib.offline.offline_prelearner import OfflinePreLearner
from ray.rllib.utils.annotations import override
from typing import Any, Dict
from ray.rllib.offline.offline_data import OfflineData
import io
from ray import data
from... |
class ImageOfflineData(OfflineData):
'''This class overrides `OfflineData` to read in raw image data.
The image data is from Ray Data`s S3 example bucket, namely
`ray-example-data/batoidea/JPEGImages/`.
To read in this data the raw bytes have to be decoded and then
converted to `numpy` arrays. Each... | 4 | 1 | 22 | 3 | 13 | 6 | 2 | 1 | 1 | 3 | 0 | 0 | 1 | 14 | 1 | 1 | 57 | 9 | 24 | 21 | 20 | 24 | 23 | 19 | 20 | 2 | 1 | 1 | 3 |
11,514 | ray-project/ray | rllib/examples/offline_rl/classes/image_offline_prelearner.py | rllib.examples.offline_rl.classes.image_offline_prelearner.ImageOfflinePreLearner | from ray.rllib.core.learner.learner import Learner
from ray.rllib.utils.typing import EpisodeType, ModuleID
from ray.rllib.offline.offline_prelearner import OfflinePreLearner, SCHEMA
import random
import uuid
from ray.rllib.core.rl_module.multi_rl_module import MultiRLModuleSpec
import gymnasium as gym
import numpy as ... |
class ImageOfflinePreLearner(OfflinePreLearner):
'''This class transforms image data to `MultiAgentBatch`es.
While the `ImageOfflineData` class transforms raw image
bytes to `numpy` arrays, this class maps these data in
`SingleAgentEpisode` instances through the learner connector
pipeline and final... | 5 | 1 | 33 | 4 | 25 | 4 | 2 | 0.38 | 1 | 6 | 1 | 0 | 1 | 9 | 2 | 2 | 84 | 12 | 52 | 33 | 30 | 20 | 19 | 15 | 16 | 3 | 1 | 2 | 4 |
11,515 | ray-project/ray | rllib/examples/offline_rl/custom_input_api.py | rllib.examples.offline_rl.custom_input_api.CustomJsonReader | from ray.rllib.offline import JsonReader, ShuffledInput, IOContext, InputReader
class CustomJsonReader(JsonReader):
"""
Example custom InputReader implementation (extended from JsonReader).
This gets wrapped in ShuffledInput to comply with offline rl algorithms.
"""
def __init__(self, ioctx: IOCo... |
class CustomJsonReader(JsonReader):
'''
Example custom InputReader implementation (extended from JsonReader).
This gets wrapped in ShuffledInput to comply with offline rl algorithms.
'''
def __init__(self, ioctx: IOContext):
'''
The constructor must take an IOContext to be used in ... | 2 | 2 | 7 | 0 | 2 | 5 | 1 | 3 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 14 | 2 | 3 | 2 | 1 | 9 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
11,516 | ray-project/ray | rllib/examples/offline_rl/train_w_bc_finetune_w_ppo.py | rllib.examples.offline_rl.train_w_bc_finetune_w_ppo.MyBCModel | from ray.rllib.core.models.configs import MLPEncoderConfig, MLPHeadConfig
from ray.rllib.core.rl_module.torch import TorchRLModule
from ray.rllib.utils.annotations import override
from ray.rllib.core.columns import Columns
from ray.rllib.core.rl_module.rl_module import RLModule, RLModuleSpec
from ray.rllib.core.models.... |
class MyBCModel(TorchRLModule):
'''A very simple BC-usable model that only computes action logits.'''
@override(TorchRLModule)
def setup(self):
pass
@override(TorchRLModule)
def _forward_inference(self, batch, **kwargs):
pass
@override(RLModule)
def _forward_exploration(self... | 9 | 1 | 6 | 0 | 5 | 2 | 1 | 0.36 | 1 | 0 | 0 | 1 | 4 | 2 | 4 | 4 | 35 | 5 | 25 | 11 | 16 | 9 | 10 | 7 | 5 | 1 | 1 | 0 | 4 |
11,517 | ray-project/ray | rllib/examples/offline_rl/train_w_bc_finetune_w_ppo.py | rllib.examples.offline_rl.train_w_bc_finetune_w_ppo.MyPPOModel | from ray.rllib.core.columns import Columns
from ray.rllib.core.models.base import ENCODER_OUT
from ray.rllib.core.rl_module.apis.value_function_api import ValueFunctionAPI
from torch import nn
from ray.rllib.utils.annotations import override
from ray.rllib.core.models.configs import MLPEncoderConfig, MLPHeadConfig
cla... |
class MyPPOModel(MyBCModel, ValueFunctionAPI):
'''Subclass of our simple BC model, but implementing the ValueFunctionAPI.
Implementing the `compute_values` method makes this RLModule usable by algos
like PPO.
'''
@override(MyBCModel)
def setup(self):
pass
@override(MyBCModel)
de... | 7 | 1 | 10 | 0 | 8 | 3 | 1 | 0.41 | 2 | 1 | 0 | 0 | 3 | 1 | 3 | 7 | 42 | 4 | 29 | 11 | 22 | 12 | 13 | 8 | 9 | 2 | 2 | 1 | 4 |
11,518 | ray-project/ray | rllib/examples/quadx_waypoints.py | rllib.examples.quadx_waypoints.RewardWrapper | import gymnasium as gym
class RewardWrapper(gym.RewardWrapper):
def __init__(self, env):
super().__init__(env)
def reward(self, reward):
if reward >= 99.0 or reward <= -99.0:
return reward / 10
return reward |
class RewardWrapper(gym.RewardWrapper):
def __init__(self, env):
pass
def reward(self, reward):
pass | 3 | 0 | 4 | 0 | 3 | 1 | 2 | 0.14 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 2 | 9 | 1 | 7 | 3 | 4 | 1 | 7 | 3 | 4 | 2 | 1 | 1 | 3 |
11,519 | ray-project/ray | rllib/examples/ray_serve/classes/cartpole_deployment.py | rllib.examples.ray_serve.classes.cartpole_deployment.ServeRLlibRLModule | import numpy as np
import torch
from ray import serve
from typing import Dict
from ray.serve.schema import LoggingConfig
from ray.rllib.core import Columns
from starlette.requests import Request
import json
from ray.rllib.core.rl_module.rl_module import RLModule
@serve.deployment(logging_config=LoggingConfig(log_level... | @serve.deployment(logging_config=LoggingConfig(log_level='WARN'))
class ServeRLlibRLModule:
'''Callable class used by Ray Serve to handle async requests.
All the necessary serving logic is implemented in here:
- Creation and restoring of the (already trained) RLlib Algorithm.
- Calls to algo.compute_act... | 4 | 1 | 10 | 1 | 7 | 2 | 1 | 0.71 | 0 | 1 | 0 | 0 | 2 | 1 | 2 | 2 | 29 | 5 | 14 | 9 | 11 | 10 | 12 | 9 | 9 | 1 | 0 | 0 | 2 |
11,520 | ray-project/ray | rllib/examples/ray_tune/custom_logger.py | rllib.examples.ray_tune.custom_logger.MyPrintLogger | from ray.rllib.utils.metrics import ENV_RUNNER_RESULTS, EPISODE_RETURN_MEAN, LEARNER_RESULTS
from ray.rllib.core import DEFAULT_MODULE_ID
from ray.tune.logger import Logger, LegacyLoggerCallback
class MyPrintLogger(Logger):
"""Logs results by simply printing out everything."""
def _init(self):
print('... |
class MyPrintLogger(Logger):
'''Logs results by simply printing out everything.'''
def _init(self):
pass
def on_result(self, result: dict):
pass
def close(self):
pass
def flush(self):
pass | 5 | 1 | 4 | 0 | 3 | 1 | 1 | 0.5 | 1 | 1 | 0 | 0 | 4 | 1 | 4 | 4 | 22 | 4 | 12 | 8 | 7 | 6 | 12 | 8 | 7 | 1 | 1 | 0 | 4 |
11,521 | ray-project/ray | rllib/examples/rl_modules/classes/action_masking_rlm.py | rllib.examples.rl_modules.classes.action_masking_rlm.ActionMaskingRLModule | import gymnasium as gym
from typing import Dict, Optional, Tuple, Union
from ray.rllib.core.rl_module.rl_module import RLModule
from ray.rllib.core.rl_module.default_model_config import DefaultModelConfig
from ray.rllib.utils.annotations import override
class ActionMaskingRLModule(RLModule):
"""An RLModule that im... |
class ActionMaskingRLModule(RLModule):
'''An RLModule that implements an action masking for safe RL.
This RLModule implements action masking to avoid unsafe/unwanted actions
dependent on the current state (observations). It does so by using an
environment generated action mask defining which actions ar... | 3 | 1 | 41 | 3 | 30 | 8 | 2 | 0.69 | 1 | 4 | 0 | 1 | 1 | 3 | 1 | 1 | 60 | 6 | 32 | 16 | 19 | 22 | 8 | 5 | 6 | 2 | 1 | 1 | 2 |
11,522 | ray-project/ray | rllib/examples/rl_modules/classes/action_masking_rlm.py | rllib.examples.rl_modules.classes.action_masking_rlm.ActionMaskingTorchRLModule | from ray.rllib.algorithms.ppo.torch.ppo_torch_rl_module import PPOTorchRLModule
from typing import Dict, Optional, Tuple, Union
from ray.rllib.core.rl_module.apis.value_function_api import ValueFunctionAPI
from ray.rllib.utils.annotations import override
from ray.rllib.core.columns import Columns
from ray.rllib.utils.t... |
class ActionMaskingTorchRLModule(ActionMaskingRLModule, PPOTorchRLModule):
@override(PPOTorchRLModule)
def setup(self):
pass
@override(PPOTorchRLModule)
def _forward_inference(self, batch: Dict[str, TensorType], **kwargs) -> Dict[str, TensorType]:
pass
@override(PPOTorchRLModule)
... | 14 | 3 | 15 | 1 | 7 | 6 | 2 | 0.75 | 2 | 4 | 0 | 0 | 8 | 2 | 8 | 9 | 132 | 18 | 65 | 34 | 41 | 49 | 36 | 19 | 27 | 4 | 2 | 2 | 12 |
11,523 | ray-project/ray | rllib/examples/rl_modules/classes/autoregressive_actions_rlm.py | rllib.examples.rl_modules.classes.autoregressive_actions_rlm.AutoregressiveActionsRLM | import gymnasium as gym
from typing import Dict
from ray.rllib.core.rl_module.torch.torch_rl_module import TorchRLModule
from ray.rllib.core.distribution.torch.torch_distribution import TorchCategorical, TorchDiagGaussian, TorchMultiDistribution
from ray.rllib.utils.torch_utils import one_hot
from ray.rllib.core import... |
class AutoregressiveActionsRLM(TorchRLModule, ValueFunctionAPI):
'''An RLModule that uses an autoregressive action distribution.
Actions are sampled in two steps. The first (prior) action component is sampled from
a categorical distribution. Then, the second (posterior) action component is sampled
from... | 14 | 1 | 12 | 1 | 10 | 1 | 1 | 0.22 | 2 | 3 | 0 | 0 | 7 | 3 | 7 | 7 | 108 | 15 | 76 | 28 | 60 | 17 | 35 | 20 | 27 | 3 | 1 | 1 | 9 |
11,524 | ray-project/ray | rllib/examples/rl_modules/classes/intrinsic_curiosity_model_rlm.py | rllib.examples.rl_modules.classes.intrinsic_curiosity_model_rlm.IntrinsicCuriosityModel | from ray.rllib.core.rl_module.torch import TorchRLModule
from typing import Any, Dict, TYPE_CHECKING
from ray.rllib.utils.typing import ModuleID
from ray.rllib.core.rl_module.apis import SelfSupervisedLossAPI
from ray.rllib.utils.torch_utils import one_hot
from ray.rllib.utils.annotations import override
import tree
fr... |
class IntrinsicCuriosityModel(TorchRLModule, SelfSupervisedLossAPI):
'''An intrinsic curiosity model (ICM) as TorchRLModule for better exploration.
For more details, see:
[1] Curiosity-driven Exploration by Self-supervised Prediction
Pathak, Agrawal, Efros, and Darrell - UC Berkeley - ICML 2017.
ht... | 9 | 1 | 35 | 4 | 25 | 7 | 3 | 0.8 | 2 | 4 | 0 | 0 | 4 | 4 | 4 | 4 | 220 | 29 | 106 | 39 | 89 | 85 | 54 | 26 | 49 | 7 | 1 | 2 | 10 |
11,525 | ray-project/ray | rllib/examples/rl_modules/classes/lstm_containing_rlm.py | rllib.examples.rl_modules.classes.lstm_containing_rlm.LSTMContainingRLModule | from ray.rllib.utils.typing import TensorType
from typing import Any, Dict, Optional
from ray.rllib.core.rl_module.torch import TorchRLModule
from ray.rllib.core.columns import Columns
import numpy as np
from ray.rllib.utils.annotations import override
from ray.rllib.core.rl_module.apis.value_function_api import ValueF... |
class LSTMContainingRLModule(TorchRLModule, ValueFunctionAPI):
'''An example TorchRLModule that contains an LSTM layer.
.. testcode::
import numpy as np
import gymnasium as gym
B = 10 # batch size
T = 5 # seq len
e = 25 # embedding dim
CELL = 32 # LSTM cell s... | 12 | 2 | 14 | 1 | 8 | 5 | 1 | 1.2 | 2 | 2 | 0 | 0 | 6 | 5 | 6 | 6 | 138 | 19 | 54 | 33 | 40 | 65 | 37 | 26 | 30 | 2 | 1 | 1 | 8 |
11,526 | ray-project/ray | rllib/examples/rl_modules/classes/mobilenet_rlm.py | rllib.examples.rl_modules.classes.mobilenet_rlm.MobileNetTorchPPORLModule | from ray.rllib.core.models.configs import ActorCriticEncoderConfig
from ray.rllib.examples._old_api_stack.models.mobilenet_v2_encoder import MobileNetV2EncoderConfig, MOBILENET_INPUT_SHAPE
from ray.rllib.core.models.configs import MLPHeadConfig
from ray.rllib.algorithms.ppo.torch.default_ppo_torch_rl_module import Defa... |
class MobileNetTorchPPORLModule(DefaultPPOTorchRLModule):
'''A DefaultPPORLModule with mobilenet v2 as an encoder.
The idea behind this model is to demonstrate how we can bypass catalog to
take full control over what models and action distribution are being built.
In this example, we do this to modify ... | 2 | 1 | 22 | 4 | 16 | 2 | 1 | 0.41 | 1 | 0 | 0 | 0 | 1 | 3 | 1 | 1 | 30 | 6 | 17 | 10 | 15 | 7 | 10 | 10 | 8 | 1 | 1 | 0 | 1 |
11,527 | ray-project/ray | rllib/examples/rl_modules/classes/modelv2_to_rlm.py | rllib.examples.rl_modules.classes.modelv2_to_rlm.ModelV2ToRLModule | from ray.rllib.core.rl_module.torch import TorchRLModule
from ray.rllib.policy.torch_policy_v2 import TorchPolicyV2
import pathlib
from typing import Any, Dict, Optional
from ray.rllib.core.rl_module.apis import ValueFunctionAPI
import tree
from ray.rllib.models.torch.torch_action_dist import TorchCategorical as OldTor... | null | 15 | 2 | 19 | 1 | 16 | 2 | 3 | 0.19 | 2 | 7 | 0 | 0 | 8 | 4 | 8 | 8 | 178 | 18 | 134 | 34 | 119 | 26 | 71 | 26 | 62 | 8 | 1 | 2 | 23 |
11,528 | ray-project/ray | rllib/examples/rl_modules/classes/random_rlm.py | rllib.examples.rl_modules.classes.random_rlm.RandomRLModule | from ray.rllib.utils.annotations import override
from ray.rllib.utils.spaces.space_utils import batch as batch_func
from ray.rllib.policy.sample_batch import SampleBatch
from ray.rllib.core.rl_module import RLModule
import tree
class RandomRLModule(RLModule):
@override(RLModule)
def _forward(self, batch, **kw... |
class RandomRLModule(RLModule):
@override(RLModule)
def _forward(self, batch, **kwargs):
pass
@override(RLModule)
def _forward_train(self, *args, **kwargs):
pass
def compile(self, *args, **kwargs):
'''Dummy method for compatibility with TorchRLModule.
This is hit w... | 6 | 1 | 4 | 0 | 3 | 1 | 1 | 0.32 | 1 | 2 | 0 | 1 | 5 | 0 | 5 | 5 | 30 | 5 | 19 | 13 | 9 | 6 | 13 | 8 | 7 | 1 | 1 | 0 | 5 |
11,529 | ray-project/ray | rllib/examples/rl_modules/classes/random_rlm.py | rllib.examples.rl_modules.classes.random_rlm.StatefulRandomRLModule | from ray.rllib.core.rl_module import RLModule
import numpy as np
from ray.rllib.core.columns import Columns
from ray.rllib.utils.annotations import override
from ray.rllib.utils.spaces.space_utils import batch as batch_func
import gymnasium as gym
class StatefulRandomRLModule(RandomRLModule):
"""A stateful RLModul... |
class StatefulRandomRLModule(RandomRLModule):
'''A stateful RLModule that returns STATE_OUT from its forward methods.
- Implements the `get_initial_state` method (returning a all-zeros dummy state).
- Returns a dummy state under the `Columns.STATE_OUT` from its forward methods.
'''
def __init__(se... | 5 | 1 | 6 | 0 | 6 | 0 | 1 | 0.2 | 1 | 2 | 0 | 0 | 3 | 1 | 3 | 8 | 28 | 4 | 20 | 7 | 15 | 4 | 10 | 5 | 6 | 1 | 2 | 0 | 3 |
11,530 | ray-project/ray | rllib/examples/rl_modules/classes/rock_paper_scissors_heuristic_rlm.py | rllib.examples.rl_modules.classes.rock_paper_scissors_heuristic_rlm.AlwaysSameHeuristicRLM | from ray.rllib.utils.annotations import override
from ray.rllib.core.rl_module.rl_module import RLModule
import numpy as np
from collections import defaultdict
from ray.rllib.core.columns import Columns
class AlwaysSameHeuristicRLM(RLModule):
"""In rock-paper-scissors, always chooses the same action within an epis... |
class AlwaysSameHeuristicRLM(RLModule):
'''In rock-paper-scissors, always chooses the same action within an episode.
The first move is random, all the following moves are the same as the first one.
'''
def __init__(self, *args, **kwargs):
pass
@override(RLModule)
def _forward_inference... | 8 | 1 | 4 | 0 | 4 | 0 | 1 | 0.19 | 1 | 4 | 0 | 0 | 6 | 1 | 6 | 6 | 39 | 7 | 27 | 15 | 15 | 5 | 19 | 10 | 12 | 3 | 1 | 2 | 8 |
11,531 | ray-project/ray | rllib/examples/rl_modules/classes/rock_paper_scissors_heuristic_rlm.py | rllib.examples.rl_modules.classes.rock_paper_scissors_heuristic_rlm.BeatLastHeuristicRLM | from ray.rllib.utils.annotations import override
import numpy as np
from ray.rllib.core.columns import Columns
from ray.rllib.core.rl_module.rl_module import RLModule
class BeatLastHeuristicRLM(RLModule):
"""In rock-paper-scissors, always acts such that it beats prev. move of opponent.
The first move is rando... |
class BeatLastHeuristicRLM(RLModule):
'''In rock-paper-scissors, always acts such that it beats prev. move of opponent.
The first move is random.
For example, after opponent played `rock` (and this policy made a random
move), the next move would be `paper`(to beat `rock`).
'''
@override(RLModul... | 9 | 2 | 6 | 0 | 4 | 2 | 2 | 0.45 | 1 | 1 | 0 | 0 | 5 | 0 | 6 | 6 | 58 | 10 | 33 | 13 | 20 | 15 | 17 | 7 | 10 | 4 | 1 | 1 | 9 |
11,532 | ray-project/ray | rllib/examples/rl_modules/classes/tiny_atari_cnn_rlm.py | rllib.examples.rl_modules.classes.tiny_atari_cnn_rlm.TinyAtariCNN | from ray.rllib.core.learner.utils import make_target_network
from ray.rllib.utils.typing import TensorType
from ray.rllib.core.rl_module.torch import TorchRLModule
from ray.rllib.models.torch.misc import normc_initializer, same_padding, valid_padding
from ray.rllib.core.columns import Columns
from ray.rllib.utils.annot... |
class TinyAtariCNN(TorchRLModule, ValueFunctionAPI, TargetNetworkAPI):
'''A tiny CNN stack for fast-learning of Atari envs.
The architecture here is the exact same as the one used by the old API stack as
CNN default ModelV2.
We stack 3 CNN layers based on the config, then a 4th one with linear activati... | 16 | 2 | 15 | 1 | 10 | 4 | 2 | 0.69 | 3 | 2 | 0 | 0 | 8 | 5 | 8 | 8 | 172 | 24 | 88 | 43 | 68 | 61 | 58 | 32 | 49 | 5 | 1 | 2 | 13 |
11,533 | ray-project/ray | rllib/examples/rl_modules/classes/vpg_torch_rlm.py | rllib.examples.rl_modules.classes.vpg_torch_rlm.VPGTorchRLModule | import torch
from ray.rllib.core.rl_module.torch import TorchRLModule
from ray.rllib.core.columns import Columns
class VPGTorchRLModule(TorchRLModule):
"""A simple VPG (vanilla policy gradient)-style RLModule for testing purposes.
Use this as a minimum, bare-bones example implementation of a custom TorchRLMod... |
class VPGTorchRLModule(TorchRLModule):
'''A simple VPG (vanilla policy gradient)-style RLModule for testing purposes.
Use this as a minimum, bare-bones example implementation of a custom TorchRLModule.
'''
def setup(self):
'''Use this method to create all the model components that you require.... | 3 | 2 | 11 | 1 | 6 | 4 | 1 | 0.85 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 28 | 4 | 13 | 8 | 10 | 11 | 9 | 8 | 6 | 1 | 1 | 0 | 2 |
11,534 | ray-project/ray | rllib/examples/rl_modules/classes/vpg_using_shared_encoder_rlm.py | rllib.examples.rl_modules.classes.vpg_using_shared_encoder_rlm.SharedEncoder | from ray.rllib.core.rl_module.torch.torch_rl_module import TorchRLModule
from ray.rllib.core import Columns
from ray.rllib.core.models.base import ENCODER_OUT
import torch
class SharedEncoder(TorchRLModule):
"""A shared encoder that can be used with `VPGMultiRLModuleWithSharedEncoder`."""
def setup(self):
... |
class SharedEncoder(TorchRLModule):
'''A shared encoder that can be used with `VPGMultiRLModuleWithSharedEncoder`.'''
def setup(self):
pass
def _forward(self, batch, **kwargs):
pass | 3 | 1 | 7 | 1 | 5 | 1 | 1 | 0.3 | 1 | 1 | 0 | 0 | 2 | 1 | 2 | 2 | 17 | 4 | 10 | 6 | 7 | 3 | 8 | 6 | 5 | 1 | 1 | 0 | 2 |
11,535 | ray-project/ray | rllib/examples/rl_modules/classes/vpg_using_shared_encoder_rlm.py | rllib.examples.rl_modules.classes.vpg_using_shared_encoder_rlm.VPGMultiRLModuleWithSharedEncoder | from typing import Any, Dict, Union
from ray.rllib.utils.annotations import override
from ray.rllib.utils.typing import ModuleID
from ray.rllib.core.rl_module.multi_rl_module import MultiRLModule
from ray.rllib.core.models.base import ENCODER_OUT
class VPGMultiRLModuleWithSharedEncoder(MultiRLModule):
"""VPG (vani... |
class VPGMultiRLModuleWithSharedEncoder(MultiRLModule):
'''VPG (vanilla pol. gradient)-style MultiRLModule handling a shared encoder.
# __sphinx_doc_mrlm_end__
This MultiRLModule needs to be configured appropriately as below.
.. testcode::
# __sphinx_doc_how_to_run_begin__
... | 9 | 1 | 14 | 3 | 8 | 4 | 2 | 4.25 | 1 | 2 | 1 | 0 | 2 | 1 | 2 | 2 | 98 | 14 | 16 | 7 | 13 | 68 | 12 | 7 | 9 | 2 | 1 | 1 | 3 |
11,536 | ray-project/ray | rllib/examples/rl_modules/classes/vpg_using_shared_encoder_rlm.py | rllib.examples.rl_modules.classes.vpg_using_shared_encoder_rlm.VPGPolicyAfterSharedEncoder | from ray.rllib.core import Columns
from ray.rllib.core.models.base import ENCODER_OUT
from ray.rllib.core.rl_module.torch.torch_rl_module import TorchRLModule
import torch
class VPGPolicyAfterSharedEncoder(TorchRLModule):
"""A VPG (vanilla pol. gradient)-style RLModule using a shared encoder.
# __sphinx_doc_po... |
class VPGPolicyAfterSharedEncoder(TorchRLModule):
'''A VPG (vanilla pol. gradient)-style RLModule using a shared encoder.
# __sphinx_doc_policy_end__
The shared encoder RLModule must be held by the same MultiRLModule, under which
this RLModule resides. The shared encoder's forward is called bef... | 3 | 1 | 9 | 1 | 7 | 1 | 1 | 0.71 | 1 | 1 | 0 | 0 | 2 | 1 | 2 | 2 | 29 | 5 | 14 | 8 | 11 | 10 | 10 | 8 | 7 | 1 | 1 | 0 | 2 |
11,537 | ray-project/ray | rllib/execution/buffers/mixin_replay_buffer.py | rllib.execution.buffers.mixin_replay_buffer.MixInMultiAgentReplayBuffer | from typing import Optional
from ray.rllib.utils.annotations import OldAPIStack
from ray.util.timer import _Timer
from ray.rllib.utils.replay_buffers.multi_agent_replay_buffer import ReplayMode
import collections
import random
from ray.rllib.execution.replay_ops import SimpleReplayBuffer
from ray.rllib.policy.sample_ba... | @OldAPIStack
class MixInMultiAgentReplayBuffer:
'''This buffer adds replayed samples to a stream of new experiences.
- Any newly added batch (`add()`) is immediately returned upon
the next `replay` call (close to on-policy) as well as being moved
into the buffer.
- Additionally, a certain number of ... | 7 | 4 | 25 | 3 | 14 | 8 | 3 | 0.96 | 0 | 6 | 1 | 0 | 4 | 10 | 4 | 4 | 158 | 25 | 68 | 28 | 55 | 65 | 50 | 21 | 44 | 6 | 0 | 3 | 15 |
11,538 | ray-project/ray | rllib/execution/learner_thread.py | rllib.execution.learner_thread.LearnerThread | from ray.rllib.execution.minibatch_buffer import MinibatchBuffer
from ray.rllib.utils.annotations import OldAPIStack
from ray.util.iter import _NextValueNotReady
import queue
from ray.rllib.utils.metrics.learner_info import LearnerInfoBuilder, LEARNER_INFO
from ray.rllib.utils.metrics.window_stat import WindowStat
impo... | @OldAPIStack
class LearnerThread(threading.Thread):
'''Background thread that updates the local model from sample trajectories.
The learner thread communicates with the main thread through Queues. This
is needed since Ray operations can only be run on the main thread. In
addition, moving heavyweight gra... | 7 | 3 | 22 | 1 | 17 | 4 | 2 | 0.31 | 1 | 5 | 2 | 0 | 4 | 14 | 4 | 29 | 119 | 9 | 84 | 31 | 71 | 26 | 49 | 24 | 43 | 5 | 1 | 2 | 12 |
11,539 | ray-project/ray | rllib/execution/minibatch_buffer.py | rllib.execution.minibatch_buffer.MinibatchBuffer | from typing import Any, Tuple
from ray.rllib.utils.annotations import OldAPIStack
import queue
@OldAPIStack
class MinibatchBuffer:
"""Ring buffer of recent data batches for minibatch SGD.
This is for use with AsyncSamplesOptimizer.
"""
def __init__(self, inqueue: queue.Queue, size: int, timeout: floa... | null | 4 | 3 | 24 | 1 | 15 | 8 | 3 | 0.63 | 0 | 5 | 0 | 0 | 2 | 8 | 2 | 2 | 54 | 5 | 30 | 20 | 20 | 19 | 23 | 13 | 20 | 4 | 0 | 2 | 5 |
11,540 | ray-project/ray | rllib/execution/multi_gpu_learner_thread.py | rllib.execution.multi_gpu_learner_thread.MultiGPULearnerThread | from ray.rllib.utils.metrics.learner_info import LearnerInfoBuilder
from ray.rllib.execution.learner_thread import LearnerThread
import queue
from ray._common.deprecation import deprecation_warning
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.execution.minibatch_buffer import MinibatchBu... | @OldAPIStack
class MultiGPULearnerThread(LearnerThread):
'''Learner that can use multiple GPUs and parallel loading.
This class is used for async sampling algorithms.
Example workflow: 2 GPUs and 3 multi-GPU tower stacks.
-> On each GPU, there are 3 slots for batches, indexed 0, 1, and 2.
Workers co... | 5 | 2 | 71 | 7 | 43 | 22 | 5 | 0.72 | 1 | 8 | 1 | 0 | 2 | 10 | 2 | 2 | 172 | 22 | 88 | 35 | 71 | 63 | 42 | 21 | 39 | 5 | 1 | 3 | 9 |
11,541 | ray-project/ray | rllib/execution/multi_gpu_learner_thread.py | rllib.execution.multi_gpu_learner_thread._MultiGPULoaderThread | import threading
from ray.util.timer import _Timer
from ray.rllib.policy.sample_batch import SampleBatch
class _MultiGPULoaderThread(threading.Thread):
def __init__(self, multi_gpu_learner_thread: MultiGPULearnerThread, share_stats: bool):
threading.Thread.__init__(self)
self.multi_gpu_learner_thr... |
class _MultiGPULoaderThread(threading.Thread):
def __init__(self, multi_gpu_learner_thread: MultiGPULearnerThread, share_stats: bool):
pass
def run(self) -> None:
pass
def _step(self) -> None:
pass | 4 | 0 | 16 | 1 | 13 | 1 | 3 | 0.1 | 1 | 3 | 2 | 0 | 3 | 4 | 3 | 28 | 51 | 6 | 41 | 16 | 35 | 4 | 28 | 14 | 24 | 5 | 1 | 3 | 9 |
11,542 | ray-project/ray | rllib/execution/replay_ops.py | rllib.execution.replay_ops.SimpleReplayBuffer | from ray.rllib.utils.annotations import OldAPIStack
from ray.rllib.utils.replay_buffers.replay_buffer import warn_replay_capacity
import random
from ray.rllib.utils.typing import SampleBatchType
from typing import Optional
@OldAPIStack
class SimpleReplayBuffer:
"""Simple replay buffer that operates over batches.""... | @OldAPIStack
class SimpleReplayBuffer:
'''Simple replay buffer that operates over batches.'''
def __init__(self, num_slots: int, replay_proportion: Optional[float]=None):
'''Initialize SimpleReplayBuffer.
Args:
num_slots: Number of batches to store in total.
'''
pass... | 6 | 2 | 6 | 0 | 4 | 1 | 2 | 0.28 | 0 | 2 | 0 | 0 | 4 | 3 | 4 | 4 | 28 | 5 | 18 | 8 | 13 | 5 | 17 | 8 | 12 | 3 | 0 | 2 | 6 |
11,543 | ray-project/ray | rllib/execution/segment_tree.py | rllib.execution.segment_tree.MinSegmentTree | from typing import Any, Optional
class MinSegmentTree(SegmentTree):
def __init__(self, capacity: int):
super(MinSegmentTree, self).__init__(capacity=capacity, operation=min)
def min(self, start: int=0, end: Optional[Any]=None) -> Any:
"""Returns min(arr[start], ..., arr[end])"""
retu... |
class MinSegmentTree(SegmentTree):
def __init__(self, capacity: int):
pass
def min(self, start: int=0, end: Optional[Any]=None) -> Any:
'''Returns min(arr[start], ..., arr[end])'''
pass | 3 | 1 | 3 | 0 | 2 | 1 | 1 | 0.2 | 1 | 3 | 0 | 0 | 2 | 0 | 2 | 8 | 7 | 1 | 5 | 3 | 2 | 1 | 5 | 3 | 2 | 1 | 1 | 0 | 2 |
11,544 | ray-project/ray | rllib/execution/segment_tree.py | rllib.execution.segment_tree.SegmentTree | import operator
from typing import Any, Optional
class SegmentTree:
"""A Segment Tree data structure.
https://en.wikipedia.org/wiki/Segment_tree
Can be used as regular array, but with two important differences:
a) Setting an item's value is slightly slower. It is O(lg capacity),
instead o... |
class SegmentTree:
'''A Segment Tree data structure.
https://en.wikipedia.org/wiki/Segment_tree
Can be used as regular array, but with two important differences:
a) Setting an item's value is slightly slower. It is O(lg capacity),
instead of O(1).
b) Offers efficient `reduce` operation... | 7 | 4 | 22 | 3 | 9 | 10 | 3 | 1.48 | 0 | 4 | 0 | 2 | 6 | 4 | 6 | 6 | 165 | 29 | 56 | 15 | 47 | 83 | 43 | 13 | 36 | 6 | 0 | 2 | 15 |
11,545 | ray-project/ray | rllib/execution/segment_tree.py | rllib.execution.segment_tree.SumSegmentTree | import operator
from typing import Any, Optional
class SumSegmentTree(SegmentTree):
"""A SegmentTree with the reduction `operation`=operator.add."""
def __init__(self, capacity: int):
super(SumSegmentTree, self).__init__(capacity=capacity, operation=operator.add)
def sum(self, start: int=0, end: ... |
class SumSegmentTree(SegmentTree):
'''A SegmentTree with the reduction `operation`=operator.add.'''
def __init__(self, capacity: int):
pass
def sum(self, start: int=0, end: Optional[Any]=None) -> Any:
'''Returns the sum over a sub-segment of the tree.'''
pass
def find_prefixs... | 4 | 3 | 9 | 1 | 5 | 3 | 2 | 0.63 | 1 | 4 | 0 | 0 | 3 | 0 | 3 | 9 | 32 | 6 | 16 | 6 | 12 | 10 | 15 | 6 | 11 | 3 | 1 | 2 | 5 |
11,546 | ray-project/ray | rllib/models/action_dist.py | rllib.models.action_dist.ActionDistribution | from ray.rllib.utils.typing import TensorType, List, Union, ModelConfigDict
from ray.rllib.utils.annotations import OldAPIStack
import gymnasium as gym
from ray.rllib.models.modelv2 import ModelV2
import numpy as np
@OldAPIStack
class ActionDistribution:
"""The policy action distribution of an agent.
Attribut... | @OldAPIStack
class ActionDistribution:
'''The policy action distribution of an agent.
Attributes:
inputs: input vector to compute samples from.
model (ModelV2): reference to model producing the inputs.
'''
def __init__(self, inputs: List[TensorType], model: ModelV2):
'''Initiali... | 14 | 11 | 7 | 1 | 2 | 4 | 1 | 1.65 | 0 | 2 | 0 | 0 | 9 | 2 | 10 | 10 | 85 | 16 | 26 | 16 | 11 | 43 | 22 | 13 | 11 | 1 | 0 | 0 | 10 |
11,547 | ray-project/ray | rllib/models/catalog.py | rllib.models.catalog.ModelCatalog | from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils.from_config import from_config
from ray.rllib.utils.spaces.simplex import Simplex
from ray.rllib.utils.annotations import DeveloperAPI, PublicAPI
import gymnasium as gym
import numpy as np
from ray.rllib.utils.error import UnsupportedSpaceException
from ... | @DeveloperAPI
class ModelCatalog:
'''Registry of models, preprocessors, and action distributions for envs.
.. testcode::
:skipif: True
prep = ModelCatalog.get_preprocessor(env)
observation = prep.transform(raw_observation)
dist_class, dist_dim = ModelCatalog.get_action_dist(
... | 36 | 10 | 57 | 5 | 41 | 11 | 7 | 0.27 | 0 | 14 | 1 | 0 | 0 | 0 | 12 | 12 | 784 | 79 | 555 | 129 | 456 | 150 | 226 | 67 | 195 | 34 | 0 | 6 | 96 |
11,548 | ray-project/ray | rllib/models/modelv2.py | rllib.models.modelv2.ModelV2 | from ray._common.deprecation import Deprecated
from ray.rllib.utils.typing import ModelConfigDict, ModelInputDict, TensorStructType
from ray.rllib.utils.framework import try_import_tf, try_import_torch, TensorType
from ray.rllib.utils import NullContextManager
from typing import Dict, List, Any, Union
from ray.rllib.ut... | null | 16 | 13 | 21 | 3 | 8 | 11 | 2 | 1.43 | 0 | 10 | 0 | 0 | 13 | 9 | 13 | 13 | 302 | 54 | 102 | 52 | 63 | 146 | 67 | 27 | 53 | 12 | 0 | 3 | 24 |
11,549 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.AtariRamPreprocessor | import gymnasium as gym
from ray.rllib.utils.annotations import OldAPIStack, override
from typing import Any, List
import numpy as np
from ray.rllib.utils.typing import TensorType
@OldAPIStack
class AtariRamPreprocessor(Preprocessor):
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options... | @OldAPIStack
class AtariRamPreprocessor(Preprocessor):
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict) -> List[int]:
pass
@override(Preprocessor)
def transform(self, observation: TensorType) -> np.ndarray:
pass | 6 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 1 | 2 | 0 | 0 | 2 | 0 | 2 | 9 | 9 | 1 | 8 | 5 | 3 | 0 | 6 | 3 | 3 | 1 | 1 | 0 | 2 |
11,550 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.DictFlatteningPreprocessor | from typing import Any, List
import numpy as np
from ray.rllib.utils.annotations import OldAPIStack, override
import gymnasium as gym
from collections import OrderedDict
from ray.rllib.utils.typing import TensorType
@OldAPIStack
class DictFlatteningPreprocessor(Preprocessor):
"""Preprocesses each dict value, then ... | @OldAPIStack
class DictFlatteningPreprocessor(Preprocessor):
'''Preprocesses each dict value, then flattens it all into a vector.
RLlib models will unpack the flattened output before _build_layers_v2().
'''
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict) -> List[in... | 8 | 1 | 10 | 0 | 10 | 0 | 2 | 0.09 | 1 | 4 | 0 | 0 | 3 | 2 | 3 | 10 | 41 | 4 | 34 | 14 | 27 | 3 | 27 | 11 | 23 | 3 | 1 | 2 | 7 |
11,551 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.GenericPixelPreprocessor | import numpy as np
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.typing import TensorType
from ray.rllib.utils.images import resize
import gymnasium as gym
from typing import Any, List
@OldAPIStack
class GenericPixelPreprocessor(Preprocessor):
"""Generic image preprocessor.
... | @OldAPIStack
class GenericPixelPreprocessor(Preprocessor):
'''Generic image preprocessor.
Note: for Atari games, use config {"preprocessor_pref": "deepmind"}
instead for deepmind-style Atari preprocessing.
'''
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict) -> ... | 6 | 2 | 15 | 1 | 12 | 3 | 3 | 0.33 | 1 | 2 | 0 | 0 | 2 | 3 | 2 | 9 | 40 | 4 | 27 | 10 | 22 | 9 | 23 | 8 | 20 | 4 | 1 | 1 | 6 |
11,552 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.MultiBinaryPreprocessor | import gymnasium as gym
from typing import Any, List
import numpy as np
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.typing import TensorType
@OldAPIStack
class MultiBinaryPreprocessor(Preprocessor):
"""Preprocessor that turns a MultiBinary space into a Box.
Note: Before ... | @OldAPIStack
class MultiBinaryPreprocessor(Preprocessor):
'''Preprocessor that turns a MultiBinary space into a Box.
Note: Before RLModules were introduced, RLlib's ModelCatalogV2 would produce
ComplexInputNetworks that treat MultiBinary spaces as Boxes. This preprocessor is
needed to get rid of the Com... | 11 | 1 | 3 | 0 | 3 | 0 | 1 | 0.41 | 1 | 2 | 0 | 0 | 4 | 1 | 4 | 11 | 29 | 5 | 17 | 10 | 7 | 7 | 12 | 6 | 7 | 1 | 1 | 0 | 4 |
11,553 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.NoPreprocessor | from typing import Any, List
from ray.rllib.utils.typing import TensorType
from ray.rllib.utils.annotations import OldAPIStack, override
import gymnasium as gym
import numpy as np
@OldAPIStack
class NoPreprocessor(Preprocessor):
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict... | @OldAPIStack
class NoPreprocessor(Preprocessor):
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict) -> List[int]:
pass
@override(Preprocessor)
def transform(self, observation: TensorType) -> np.ndarray:
pass
@override(Preprocessor)
def write(self,... | 11 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 2 | 0 | 0 | 4 | 0 | 4 | 11 | 18 | 3 | 15 | 9 | 5 | 0 | 10 | 5 | 5 | 1 | 1 | 0 | 4 |
11,554 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.OneHotPreprocessor | from ray.rllib.utils.typing import TensorType
from ray.rllib.utils.annotations import OldAPIStack, override
import gymnasium as gym
import numpy as np
from typing import Any, List
@OldAPIStack
class OneHotPreprocessor(Preprocessor):
"""One-hot preprocessor for Discrete and MultiDiscrete spaces.
.. testcode::
... | @OldAPIStack
class OneHotPreprocessor(Preprocessor):
'''One-hot preprocessor for Discrete and MultiDiscrete spaces.
.. testcode::
:skipif: True
self.transform(Discrete(3).sample())
.. testoutput::
np.array([0.0, 1.0, 0.0])
.. testcode::
:skipif: True
self.transfor... | 8 | 1 | 3 | 0 | 3 | 0 | 1 | 0.86 | 1 | 2 | 0 | 0 | 3 | 0 | 3 | 10 | 37 | 11 | 14 | 7 | 7 | 12 | 10 | 4 | 6 | 2 | 1 | 1 | 4 |
11,555 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.Preprocessor | from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.spaces.space_utils import convert_element_to_space_type
import gymnasium as gym
from ray.rllib.utils.typing import TensorType
from typing import Any, List
import numpy as np
@OldAPIStack
class Preprocessor:
"""Defines an abstract ob... | @OldAPIStack
class Preprocessor:
'''Defines an abstract observation preprocessor function.
Attributes:
shape (List[int]): Shape of the preprocessed output.
'''
def __init__(self, obs_space: gym.Space, options: dict=None):
pass
def _init_shape(self, obs_space: gym.Space, options: di... | 11 | 5 | 10 | 0 | 9 | 1 | 2 | 0.17 | 0 | 14 | 6 | 8 | 7 | 6 | 7 | 7 | 84 | 9 | 64 | 20 | 53 | 11 | 38 | 17 | 29 | 7 | 0 | 3 | 15 |
11,556 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.RepeatedValuesPreprocessor | import numpy as np
from typing import Any, List
from ray.rllib.utils.typing import TensorType
import gymnasium as gym
from ray.rllib.utils.spaces.repeated import Repeated
from ray.rllib.utils.annotations import OldAPIStack, override
@OldAPIStack
class RepeatedValuesPreprocessor(Preprocessor):
"""Pads and batches t... | @OldAPIStack
class RepeatedValuesPreprocessor(Preprocessor):
'''Pads and batches the variable-length list value.'''
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict) -> List[int]:
pass
@override(Preprocessor)
def transform(self, observation: TensorType) -> np... | 8 | 1 | 11 | 0 | 11 | 1 | 3 | 0.11 | 1 | 5 | 0 | 0 | 3 | 1 | 3 | 10 | 42 | 3 | 36 | 14 | 29 | 4 | 23 | 11 | 19 | 4 | 1 | 2 | 8 |
11,557 | ray-project/ray | rllib/models/preprocessors.py | rllib.models.preprocessors.TupleFlatteningPreprocessor | import gymnasium as gym
from typing import Any, List
import numpy as np
from ray.rllib.utils.typing import TensorType
from ray.rllib.utils.annotations import OldAPIStack, override
@OldAPIStack
class TupleFlatteningPreprocessor(Preprocessor):
"""Preprocesses each tuple element, then flattens it all into a vector.
... | @OldAPIStack
class TupleFlatteningPreprocessor(Preprocessor):
'''Preprocesses each tuple element, then flattens it all into a vector.
RLlib models will unpack the flattened output before _build_layers_v2().
'''
@override(Preprocessor)
def _init_shape(self, obs_space: gym.Space, options: dict) -> Lis... | 8 | 1 | 9 | 0 | 9 | 0 | 2 | 0.1 | 1 | 4 | 0 | 0 | 3 | 2 | 3 | 10 | 37 | 4 | 30 | 15 | 23 | 3 | 26 | 12 | 22 | 3 | 1 | 2 | 6 |
11,558 | ray-project/ray | rllib/models/repeated_values.py | rllib.models.repeated_values.RepeatedValues | from ray.rllib.utils.annotations import OldAPIStack
from typing import List
from ray.rllib.utils.typing import TensorType, TensorStructType
@OldAPIStack
class RepeatedValues:
"""Represents a variable-length list of items from spaces.Repeated.
RepeatedValues are created when you use spaces.Repeated, and are
... | @OldAPIStack
class RepeatedValues:
'''Represents a variable-length list of items from spaces.Repeated.
RepeatedValues are created when you use spaces.Repeated, and are
accessible as part of input_dict["obs"] in ModelV2 forward functions.
Example:
Suppose the gym space definition was:
... | 7 | 3 | 21 | 5 | 7 | 9 | 2 | 1.95 | 0 | 3 | 0 | 0 | 5 | 4 | 5 | 5 | 146 | 37 | 37 | 17 | 31 | 72 | 30 | 17 | 24 | 6 | 0 | 3 | 10 |
11,559 | ray-project/ray | rllib/models/tf/attention_net.py | rllib.models.tf.attention_net.AttentionWrapper | from ray.rllib.utils.tf_utils import flatten_inputs_to_1d_tensor, one_hot
from ray._common.deprecation import deprecation_warning
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.typing import ModelConfigDict, TensorType, List
from ray.util import log_once
from ray.rllib.models.modelv2... |
class AttentionWrapper(TFModelV2):
'''GTrXL wrapper serving as interface for ModelV2s that set use_attention.'''
def __init__(self, obs_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: int, model_config: ModelConfigDict, name: str):
pass
@override(RecurrentNetwork)
def for... | 8 | 1 | 46 | 5 | 35 | 6 | 6 | 0.17 | 1 | 6 | 1 | 0 | 4 | 12 | 4 | 4 | 191 | 23 | 143 | 43 | 123 | 25 | 66 | 26 | 61 | 11 | 1 | 4 | 22 |
11,560 | ray-project/ray | rllib/models/tf/attention_net.py | rllib.models.tf.attention_net.GTrXLNet | from ray.rllib.policy.view_requirement import ViewRequirement
from ray.rllib.policy.sample_batch import SampleBatch
from ray.rllib.models.tf.recurrent_net import RecurrentNetwork
from typing import Any, Dict, Optional, Union
import numpy as np
import gymnasium as gym
from ray.rllib.utils.typing import ModelConfigDict, ... |
class GTrXLNet(RecurrentNetwork):
'''A GTrXL net Model described in [2].
This is still in an experimental phase.
Can be used as a drop-in replacement for LSTMs in PPO and IMPALA.
To use this network as a replacement for an RNN, configure your Algorithm
as follows:
Examples:
>> config["m... | 8 | 2 | 44 | 4 | 29 | 11 | 2 | 0.5 | 1 | 6 | 1 | 0 | 4 | 12 | 4 | 4 | 204 | 22 | 121 | 53 | 95 | 61 | 52 | 31 | 47 | 4 | 1 | 1 | 8 |
11,561 | ray-project/ray | rllib/models/tf/attention_net.py | rllib.models.tf.attention_net.PositionwiseFeedforward | from ray.rllib.utils.typing import ModelConfigDict, TensorType, List
from ray.util import log_once
from typing import Any, Dict, Optional, Union
from ray.rllib.utils.annotations import OldAPIStack, override
from ray._common.deprecation import deprecation_warning
@OldAPIStack
class PositionwiseFeedforward(tf.keras.laye... | @OldAPIStack
class PositionwiseFeedforward(tf.keras.layers.Layer if tf else object):
'''A 2x linear layer with ReLU activation in between described in [1].
Each timestep coming from the attention head will be passed through this
layer separately.
'''
def __init__(self, out_dim: int, hidden_dim: int... | 4 | 1 | 13 | 1 | 12 | 0 | 2 | 0.17 | 0 | 3 | 0 | 0 | 2 | 2 | 2 | 2 | 33 | 5 | 24 | 12 | 15 | 4 | 11 | 6 | 8 | 2 | 0 | 1 | 3 |
11,562 | ray-project/ray | rllib/models/tf/attention_net.py | rllib.models.tf.attention_net.TrXLNet | from ray.rllib.utils.annotations import OldAPIStack, override
import numpy as np
import gymnasium as gym
from ray.util import log_once
from ray._common.deprecation import deprecation_warning
from ray.rllib.utils.typing import ModelConfigDict, TensorType, List
from ray.rllib.models.tf.recurrent_net import RecurrentNetwo... | @OldAPIStack
class TrXLNet(RecurrentNetwork):
'''A TrXL net Model described in [1].'''
def __init__(self, observation_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: int, model_config: ModelConfigDict, name: str, num_transformer_units: int, attention_dim: int, num_heads: int, head_dim: in... | 7 | 2 | 31 | 2 | 20 | 9 | 2 | 0.44 | 1 | 5 | 1 | 0 | 3 | 8 | 3 | 3 | 100 | 10 | 63 | 36 | 43 | 28 | 28 | 19 | 24 | 3 | 1 | 1 | 5 |
11,563 | ray-project/ray | rllib/models/tf/complex_input_net.py | rllib.models.tf.complex_input_net.ComplexInputNetwork | import numpy as np
from ray.rllib.models.tf.misc import normc_initializer
from ray.rllib.models.catalog import ModelCatalog
from ray.rllib.models.utils import get_filter_config
from ray.rllib.utils.annotations import OldAPIStack, override
from gymnasium.spaces import Box, Discrete, MultiDiscrete
import tree
from ray.rl... | @OldAPIStack
class ComplexInputNetwork(TFModelV2):
'''TFModelV2 concat'ing CNN outputs to flat input(s), followed by FC(s).
Note: This model should be used for complex (Dict or Tuple) observation
spaces that have one or more image components.
The data flow is as follows:
`obs` (e.g. Tuple[img0, img1... | 7 | 1 | 58 | 3 | 50 | 4 | 6 | 0.14 | 1 | 4 | 0 | 0 | 3 | 12 | 3 | 3 | 191 | 15 | 154 | 35 | 148 | 22 | 62 | 32 | 58 | 9 | 1 | 3 | 17 |
11,564 | ray-project/ray | rllib/models/tf/fcnet.py | rllib.models.tf.fcnet.FullyConnectedNetwork | from ray.rllib.models.tf.tf_modelv2 import TFModelV2
from ray.rllib.models.tf.misc import normc_initializer
import gymnasium as gym
from ray.rllib.models.utils import get_activation_fn
import numpy as np
from ray.rllib.utils.annotations import OldAPIStack
from ray.rllib.utils.typing import TensorType, List, ModelConfig... | @OldAPIStack
class FullyConnectedNetwork(TFModelV2):
'''Generic fully connected network implemented in ModelV2 API.'''
def __init__(self, obs_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: int, model_config: ModelConfigDict, name: str):
pass
def tiled_log_std(x):
... | 6 | 1 | 33 | 3 | 27 | 3 | 4 | 0.13 | 1 | 4 | 0 | 0 | 3 | 4 | 3 | 3 | 133 | 14 | 105 | 34 | 88 | 14 | 48 | 22 | 43 | 12 | 1 | 2 | 15 |
11,565 | ray-project/ray | rllib/models/tf/layers/gru_gate.py | rllib.models.tf.layers.gru_gate.GRUGate | from ray.rllib.utils.typing import TensorType, TensorShape
from ray.util import log_once
from ray._common.deprecation import deprecation_warning
class GRUGate(tf.keras.layers.Layer if tf else object):
def __init__(self, init_bias: float=0.0, **kwargs):
super().__init__(**kwargs)
self._init_bias = ... |
class GRUGate(tf.keras.layers.Layer if tf else object):
def __init__(self, init_bias: float=0.0, **kwargs):
pass
def build(self, input_shape: TensorShape):
pass
def bias_initializer(shape, dtype):
pass
def call(self, inputs: TensorType, **kwargs) -> TensorType:
... | 5 | 0 | 12 | 2 | 10 | 0 | 2 | 0.03 | 0 | 4 | 0 | 0 | 3 | 8 | 3 | 3 | 50 | 10 | 39 | 19 | 34 | 1 | 29 | 19 | 24 | 2 | 0 | 1 | 6 |
11,566 | ray-project/ray | rllib/models/tf/layers/multi_head_attention.py | rllib.models.tf.layers.multi_head_attention.MultiHeadAttention | from ray.rllib.utils.typing import TensorType
from ray._common.deprecation import deprecation_warning
from ray.util import log_once
class MultiHeadAttention(tf.keras.layers.Layer if tf else object):
"""A multi-head attention layer described in [1]."""
def __init__(self, out_dim: int, num_heads: int, head_dim:... |
class MultiHeadAttention(tf.keras.layers.Layer if tf else object):
'''A multi-head attention layer described in [1].'''
def __init__(self, out_dim: int, num_heads: int, head_dim: int, **kwargs):
pass
def call(self, inputs: TensorType) -> TensorType:
pass | 3 | 1 | 22 | 4 | 17 | 3 | 2 | 0.2 | 0 | 2 | 0 | 0 | 2 | 4 | 2 | 2 | 48 | 10 | 35 | 18 | 32 | 7 | 29 | 18 | 26 | 2 | 0 | 1 | 3 |
11,567 | ray-project/ray | rllib/models/tf/layers/noisy_layer.py | rllib.models.tf.layers.noisy_layer.NoisyLayer | from ray.rllib.models.utils import get_activation_fn
import numpy as np
from ray.util import log_once
from ray.rllib.utils.framework import get_variable, try_import_tf, TensorType, TensorShape
from ray._common.deprecation import deprecation_warning
class NoisyLayer(tf.keras.layers.Layer if tf else object):
"""A La... |
class NoisyLayer(tf.keras.layers.Layer if tf else object):
'''A Layer that adds learnable Noise to some previous layer's outputs.
Consists of:
- a common dense layer: y = w^{T}x + b
- a noisy layer: y = (w + \epsilon_w*\sigma_w)^{T}x +
(b+\epsilon_b*\sigma_b)
, where \epsilon are random var... | 5 | 2 | 22 | 2 | 18 | 4 | 2 | 0.35 | 0 | 4 | 0 | 0 | 4 | 8 | 4 | 4 | 103 | 12 | 71 | 23 | 64 | 25 | 34 | 21 | 29 | 2 | 0 | 1 | 6 |
11,568 | ray-project/ray | rllib/models/tf/layers/relative_multi_head_attention.py | rllib.models.tf.layers.relative_multi_head_attention.PositionalEmbedding | class PositionalEmbedding(tf.keras.layers.Layer if tf else object):
def __init__(self, out_dim, **kwargs):
super().__init__(**kwargs)
self.inverse_freq = 1 / 10000 ** (tf.range(0, out_dim, 2.0) / out_dim)
def call(self, seq_length):
pos_offsets = tf.cast(tf.range(seq_length - 1, -1, -1... | class PositionalEmbedding(tf.keras.layers.Layer if tf else object):
def __init__(self, out_dim, **kwargs):
pass
def call(self, seq_length):
pass | 3 | 0 | 4 | 0 | 4 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 2 | 1 | 2 | 2 | 9 | 1 | 8 | 6 | 5 | 0 | 8 | 6 | 5 | 1 | 0 | 0 | 2 |
11,569 | ray-project/ray | rllib/models/tf/layers/relative_multi_head_attention.py | rllib.models.tf.layers.relative_multi_head_attention.RelativeMultiHeadAttention | from ray.util import log_once
from ray._common.deprecation import deprecation_warning
from ray.rllib.utils.typing import TensorType
from typing import Optional
class RelativeMultiHeadAttention(tf.keras.layers.Layer if tf else object):
"""A RelativeMultiHeadAttention layer as described in [3].
Uses segment lev... |
class RelativeMultiHeadAttention(tf.keras.layers.Layer if tf else object):
'''A RelativeMultiHeadAttention layer as described in [3].
Uses segment level recurrence with state reuse.
'''
def __init__(self, out_dim: int, num_heads: int, head_dim: int, input_layernorm: bool=False, output_activation: Opti... | 5 | 2 | 39 | 6 | 22 | 12 | 2 | 0.59 | 0 | 4 | 1 | 0 | 2 | 9 | 3 | 3 | 126 | 21 | 68 | 38 | 53 | 40 | 51 | 27 | 47 | 3 | 0 | 1 | 6 |
11,570 | ray-project/ray | rllib/models/tf/layers/skip_connection.py | rllib.models.tf.layers.skip_connection.SkipConnection | from ray._common.deprecation import deprecation_warning
from ray.util import log_once
from ray.rllib.utils.typing import TensorType
from typing import Optional, Any
class SkipConnection(tf.keras.layers.Layer if tf else object):
"""Skip connection layer.
Adds the original input to the output (regular residual ... |
class SkipConnection(tf.keras.layers.Layer if tf else object):
'''Skip connection layer.
Adds the original input to the output (regular residual layer) OR uses
input as hidden state input to a given fan_in_layer.
'''
def __init__(self, layer: Any, fan_in_layer: Optional[Any]=None, **kwargs):
... | 3 | 2 | 14 | 1 | 8 | 6 | 2 | 0.94 | 0 | 2 | 0 | 0 | 2 | 2 | 2 | 2 | 36 | 5 | 16 | 6 | 13 | 15 | 13 | 6 | 10 | 2 | 0 | 1 | 4 |
11,571 | ray-project/ray | rllib/models/tf/recurrent_net.py | rllib.models.tf.recurrent_net.LSTMWrapper | from typing import Dict, List, Tuple
from ray.rllib.policy.sample_batch import SampleBatch
import logging
from ray.rllib.policy.view_requirement import ViewRequirement
from gymnasium.spaces import Discrete, MultiDiscrete
from ray.rllib.utils.spaces.space_utils import get_base_struct_from_space
from ray.rllib.models.mod... | @OldAPIStack
class LSTMWrapper(RecurrentNetwork):
'''An LSTM wrapper serving as an interface for ModelV2s that set use_lstm.'''
def __init__(self, obs_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: int, model_config: ModelConfigDict, name: str):
pass
@override(RecurrentNetwor... | 11 | 1 | 30 | 3 | 22 | 5 | 4 | 0.22 | 1 | 3 | 0 | 0 | 5 | 9 | 5 | 8 | 160 | 20 | 115 | 44 | 91 | 25 | 59 | 25 | 53 | 11 | 2 | 3 | 20 |
11,572 | ray-project/ray | rllib/models/tf/recurrent_net.py | rllib.models.tf.recurrent_net.RecurrentNetwork | from ray.util.debug import log_once
from typing import Dict, List, Tuple
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.models.tf.tf_modelv2 import TFModelV2
from ray._common.deprecation import deprecation_warning
from ray.rllib.utils.typing import ModelConfigDict, TensorType
from ray.rlli... | @OldAPIStack
class RecurrentNetwork(TFModelV2):
'''Helper class to simplify implementing RNN models with TFModelV2.
Instead of implementing forward(), you can implement forward_rnn() which
takes batches with the time dimension added already.
Here is an example implementation for a subclass
``MyRNNCl... | 6 | 4 | 22 | 3 | 9 | 10 | 1 | 2 | 1 | 2 | 0 | 1 | 3 | 0 | 3 | 3 | 104 | 17 | 29 | 15 | 17 | 58 | 13 | 7 | 9 | 2 | 1 | 1 | 4 |
11,573 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.Beta | from ray.rllib.models.action_dist import ActionDistribution
from math import log
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils import MIN_LOG_NN_OUTPUT, MAX_LOG_NN_OUTPUT, SMALL_NUMBER
import gymnasium as gym
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
from ray... | @OldAPIStack
class Beta(TFActionDistribution):
'''
A Beta distribution is defined on the interval [0, 1] and parameterized by
shape parameters alpha and beta (also called concentration parameters).
PDF(x; alpha, beta) = x**(alpha - 1) (1 - x)**(beta - 1) / Z
with Z = Gamma(alpha) Gamma(beta) / G... | 14 | 1 | 5 | 0 | 4 | 0 | 1 | 0.25 | 1 | 3 | 0 | 0 | 6 | 3 | 7 | 11 | 53 | 8 | 36 | 26 | 15 | 9 | 23 | 14 | 15 | 1 | 2 | 0 | 7 |
11,574 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.Categorical | from ray.rllib.models.action_dist import ActionDistribution
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils.annotations import OldAPIStack, override
@OldAPIStack
class Categorical(TFActionDistribution):
"""Categori... | @OldAPIStack
class Categorical(TFActionDistribution):
'''Categorical distribution for discrete action spaces.'''
def __init__(self, inputs: List[TensorType], model: ModelV2=None, temperature: float=1.0):
pass
@override(ActionDistribution)
def deterministic_sample(self) -> TensorType:
pa... | 16 | 1 | 5 | 0 | 4 | 0 | 1 | 0.08 | 1 | 2 | 0 | 2 | 6 | 1 | 7 | 11 | 48 | 7 | 38 | 28 | 21 | 3 | 27 | 19 | 19 | 1 | 2 | 0 | 7 |
11,575 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.Deterministic | import gymnasium as gym
from ray.rllib.models.action_dist import ActionDistribution
from ray.rllib.utils.annotations import OldAPIStack, override
import numpy as np
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
@OldAPIStack
class Deterministic(TFActionDistribution):
"""Action d... | @OldAPIStack
class Deterministic(TFActionDistribution):
'''Action distribution that returns the input values directly.
This is similar to DiagGaussian with standard deviation zero (thus only
requiring the "mean" values as NN output).
'''
@override(ActionDistribution)
def deterministic_sample(sel... | 11 | 1 | 3 | 0 | 3 | 0 | 1 | 0.25 | 1 | 1 | 0 | 0 | 3 | 0 | 4 | 8 | 25 | 5 | 16 | 11 | 4 | 4 | 9 | 5 | 4 | 1 | 2 | 0 | 4 |
11,576 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.DiagGaussian | import numpy as np
from ray.rllib.models.modelv2 import ModelV2
import gymnasium as gym
from ray.rllib.models.action_dist import ActionDistribution
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
from typing import Optional... | @OldAPIStack
class DiagGaussian(TFActionDistribution):
'''Action distribution where each vector element is a gaussian.
The first half of the input vector defines the gaussian means, and the
second half the gaussian standard deviations.
'''
def __init__(self, inputs: List[TensorType], model: ModelV2... | 16 | 1 | 7 | 0 | 7 | 0 | 1 | 0.11 | 1 | 2 | 0 | 0 | 6 | 4 | 7 | 11 | 69 | 8 | 55 | 28 | 32 | 6 | 26 | 14 | 18 | 2 | 2 | 1 | 9 |
11,577 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.Dirichlet | from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
from ray.rllib.models.action_dist import ActionDistribution
import numpy as np
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils.annotations import OldAPIStack, override
import gymnasium as gym
@OldAPIStack
class Dirichl... | @OldAPIStack
class Dirichlet(TFActionDistribution):
'''Dirichlet distribution for continuous actions that are between
[0,1] and sum to 1.
e.g. actions that represent resource allocation.'''
def __init__(self, inputs: List[TensorType], model: ModelV2):
'''Input is a tensor of logits. The exponen... | 16 | 2 | 5 | 0 | 4 | 1 | 1 | 0.36 | 1 | 2 | 0 | 0 | 6 | 2 | 7 | 11 | 54 | 9 | 33 | 19 | 16 | 12 | 20 | 11 | 12 | 1 | 2 | 0 | 7 |
11,578 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.GumbelSoftmax | from ray.rllib.models.modelv2 import ModelV2
import gymnasium as gym
from ray.rllib.utils.annotations import OldAPIStack, override
import numpy as np
from ray.rllib.models.action_dist import ActionDistribution
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
@OldAPIStack
class GumbelS... | @OldAPIStack
class GumbelSoftmax(TFActionDistribution):
'''GumbelSoftmax distr. (for differentiable sampling in discr. actions
The Gumbel Softmax distribution [1] (also known as the Concrete [2]
distribution) is a close cousin of the relaxed one-hot categorical
distribution, whose tfp implementation we ... | 12 | 2 | 9 | 0 | 6 | 2 | 1 | 0.69 | 1 | 3 | 0 | 0 | 4 | 2 | 5 | 9 | 69 | 10 | 35 | 17 | 20 | 24 | 17 | 9 | 11 | 2 | 2 | 1 | 6 |
11,579 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.MultiActionDistribution | import numpy as np
from ray.rllib.models.action_dist import ActionDistribution
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.spaces.space_utils import get_base_struct_from_space
import functools
import tree
@OldAPIStack
class MultiActionDistribution(TFActionDistribution):
"""Ac... | @OldAPIStack
class MultiActionDistribution(TFActionDistribution):
'''Action distribution that operates on a set of actions.
Args:
inputs (Tensor list): A list of tensors from which to compute samples.
'''
def __init__(self, inputs, model, *, child_distributions, input_lens, action_space, **kwar... | 18 | 1 | 10 | 1 | 8 | 1 | 2 | 0.13 | 1 | 3 | 2 | 0 | 8 | 3 | 8 | 12 | 101 | 14 | 77 | 34 | 58 | 10 | 45 | 25 | 35 | 6 | 2 | 4 | 17 |
11,580 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.MultiCategorical | from ray.rllib.models.action_dist import ActionDistribution
import gymnasium as gym
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
import numpy as np
@OldAPIStack
class MultiCa... | @OldAPIStack
class MultiCategorical(TFActionDistribution):
'''MultiCategorical distribution for MultiDiscrete action spaces.'''
def __init__(self, inputs: List[TensorType], model: ModelV2, input_lens: Union[List[int], np.ndarray, Tuple[int, ...]], action_space=None):
pass
@override(ActionDistributi... | 20 | 1 | 8 | 0 | 8 | 1 | 2 | 0.08 | 1 | 4 | 1 | 0 | 8 | 4 | 9 | 13 | 93 | 9 | 78 | 35 | 51 | 6 | 44 | 19 | 34 | 4 | 2 | 2 | 16 |
11,581 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.SlateMultiCategorical | from ray.rllib.models.action_dist import ActionDistribution
import gymnasium as gym
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
from typing import Optional
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.models.modelv2 import ModelV2
@OldAPIStack
clas... | @OldAPIStack
class SlateMultiCategorical(Categorical):
'''MultiCategorical distribution for MultiDiscrete action spaces.
The action space must be uniform, meaning all nvec items have the same size, e.g.
MultiDiscrete([10, 10, 10]), where 10 is the number of candidates to pick from
and 3 is the slate siz... | 7 | 1 | 9 | 0 | 7 | 2 | 1 | 0.57 | 1 | 2 | 0 | 0 | 3 | 2 | 3 | 14 | 40 | 4 | 23 | 16 | 10 | 13 | 12 | 7 | 8 | 1 | 3 | 0 | 3 |
11,582 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.SquashedGaussian | import numpy as np
from ray.rllib.utils import MIN_LOG_NN_OUTPUT, MAX_LOG_NN_OUTPUT, SMALL_NUMBER
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.models.action_dist import ActionDistribution
import gymnasium as gym
from ray.rllib.utils.typing imp... | @OldAPIStack
class SquashedGaussian(TFActionDistribution):
'''A tanh-squashed Gaussian distribution defined by: mean, std, low, high.
The distribution will never return low or high exactly, but
`low`+SMALL_NUMBER or `high`-SMALL_NUMBER respectively.
'''
def __init__(self, inputs: List[TensorType], ... | 19 | 2 | 7 | 0 | 6 | 1 | 1 | 0.27 | 1 | 4 | 0 | 0 | 9 | 3 | 10 | 14 | 96 | 12 | 66 | 41 | 40 | 18 | 42 | 27 | 31 | 1 | 2 | 0 | 10 |
11,583 | ray-project/ray | rllib/models/tf/tf_action_dist.py | rllib.models.tf.tf_action_dist.TFActionDistribution | from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.models.action_dist import ActionDistribution
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils.typing import TensorType, List, Union, Tuple, ModelConfigDict
@OldAPIStack
class TFActionDistribution(ActionDistribution):
"""T... | @OldAPIStack
class TFActionDistribution(ActionDistribution):
'''TF-specific extensions for building action distributions.'''
@override(ActionDistribution)
def __init__(self, inputs: List[TensorType], model: ModelV2):
pass
def _build_sample_op(self) -> TensorType:
'''Implement this inste... | 9 | 4 | 4 | 0 | 3 | 2 | 1 | 0.5 | 1 | 2 | 0 | 9 | 4 | 2 | 4 | 4 | 26 | 5 | 14 | 10 | 6 | 7 | 11 | 7 | 6 | 1 | 1 | 0 | 4 |
11,584 | ray-project/ray | rllib/models/tf/tf_modelv2.py | rllib.models.tf.tf_modelv2.TFModelV2 | from ray.rllib.utils.typing import ModelConfigDict, TensorType
import contextlib
from ray.rllib.models.modelv2 import ModelV2
import re
from ray._common.deprecation import deprecation_warning
from typing import Dict, List, Union
import gymnasium as gym
from ray.util import log_once
from ray.rllib.utils.annotations impo... | @OldAPIStack
class TFModelV2(ModelV2):
'''TF version of ModelV2, which should contain a tf keras Model.
Note that this class by itself is not a valid model unless you
implement forward() in a subclass.'''
def __init__(self, obs_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: i... | 12 | 5 | 16 | 1 | 11 | 4 | 3 | 0.35 | 1 | 9 | 0 | 0 | 6 | 2 | 7 | 7 | 126 | 14 | 83 | 30 | 61 | 29 | 52 | 16 | 44 | 10 | 1 | 2 | 23 |
11,585 | ray-project/ray | rllib/models/tf/visionnet.py | rllib.models.tf.visionnet.VisionNetwork | from typing import Dict, List
from ray.rllib.utils.typing import ModelConfigDict, TensorType
from ray.rllib.models.tf.misc import normc_initializer
from ray.rllib.utils.annotations import OldAPIStack
from ray.rllib.models.tf.tf_modelv2 import TFModelV2
import gymnasium as gym
from ray.rllib.models.utils import get_acti... | @OldAPIStack
class VisionNetwork(TFModelV2):
'''Generic vision network implemented in ModelV2 API.
An additional post-conv fully connected stack can be added and configured
via the config keys:
`post_fcnet_hiddens`: Dense layer sizes after the Conv2D stack.
`post_fcnet_activation`: Activation functi... | 5 | 1 | 80 | 6 | 67 | 7 | 8 | 0.13 | 1 | 7 | 0 | 0 | 3 | 5 | 3 | 3 | 250 | 21 | 202 | 37 | 186 | 27 | 67 | 25 | 63 | 21 | 1 | 4 | 25 |
11,586 | ray-project/ray | rllib/models/torch/attention_net.py | rllib.models.torch.attention_net.AttentionWrapper | from ray._common.deprecation import deprecation_warning
import tree
from ray.rllib.utils.typing import ModelConfigDict, TensorType, List
import numpy as np
from ray.rllib.policy.view_requirement import ViewRequirement
from ray.rllib.models.modelv2 import ModelV2
from ray.rllib.utils.spaces.space_utils import get_base_s... |
class AttentionWrapper(TorchModelV2, nn.Module):
'''GTrXL wrapper serving as interface for ModelV2s that set use_attention.'''
def __init__(self, obs_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: int, model_config: ModelConfigDict, name: str):
pass
@override(RecurrentNetwor... | 8 | 1 | 47 | 5 | 37 | 6 | 6 | 0.15 | 2 | 6 | 1 | 0 | 4 | 12 | 4 | 4 | 197 | 22 | 152 | 41 | 132 | 23 | 64 | 24 | 59 | 11 | 1 | 4 | 22 |
11,587 | ray-project/ray | rllib/models/torch/attention_net.py | rllib.models.torch.attention_net.GTrXLNet | from gymnasium.spaces import Box, Discrete, MultiDiscrete
import gymnasium as gym
from ray.rllib.utils.typing import ModelConfigDict, TensorType, List
from ray.rllib.models.torch.misc import SlimFC
from ray.rllib.policy.sample_batch import SampleBatch
from ray.rllib.utils.annotations import OldAPIStack, override
import... | @OldAPIStack
class GTrXLNet(RecurrentNetwork, nn.Module):
'''A GTrXL net Model described in [2].
This is still in an experimental phase.
Can be used as a drop-in replacement for LSTMs in PPO and IMPALA.
To use this network as a replacement for an RNN, configure your Algorithm
as follows:
Example... | 9 | 2 | 48 | 4 | 32 | 12 | 3 | 0.5 | 2 | 6 | 0 | 0 | 4 | 15 | 4 | 4 | 219 | 24 | 130 | 54 | 104 | 65 | 58 | 32 | 53 | 4 | 1 | 2 | 10 |
11,588 | ray-project/ray | rllib/models/torch/complex_input_net.py | rllib.models.torch.complex_input_net.ComplexInputNetwork | from ray.rllib.utils.torch_utils import one_hot
from ray.rllib.utils.spaces.space_utils import flatten_space
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.policy.sample_batch import SampleBatch
from gymnasium.spaces import Box, Discrete, MultiDiscrete
from ray.rllib.models.torch.misc impo... | @OldAPIStack
class ComplexInputNetwork(TorchModelV2, nn.Module):
'''TorchModelV2 concat'ing CNN outputs to flat input(s), followed by FC(s).
Note: This model should be used for complex (Dict or Tuple) observation
spaces that have one or more image components.
The data flow is as follows:
`obs` (e.g.... | 7 | 1 | 66 | 4 | 53 | 9 | 6 | 0.22 | 2 | 4 | 0 | 0 | 3 | 13 | 3 | 3 | 215 | 18 | 162 | 33 | 156 | 35 | 67 | 30 | 63 | 9 | 1 | 3 | 17 |
11,589 | ray-project/ray | rllib/models/torch/fcnet.py | rllib.models.torch.fcnet.FullyConnectedNetwork | import numpy as np
from ray.rllib.models.torch.misc import SlimFC, AppendBiasLayer, normc_initializer
from ray.rllib.utils.annotations import OldAPIStack, override
from ray.rllib.utils.typing import Dict, TensorType, List, ModelConfigDict
import gymnasium as gym
from ray.rllib.models.torch.torch_modelv2 import TorchMod... | @OldAPIStack
class FullyConnectedNetwork(TorchModelV2, nn.Module):
'''Generic fully connected network.'''
def __init__(self, obs_space: gym.spaces.Space, action_space: gym.spaces.Space, num_outputs: int, model_config: ModelConfigDict, name: str):
pass
@override(TorchModelV2)
def forward(self, i... | 7 | 1 | 46 | 3 | 39 | 4 | 5 | 0.1 | 2 | 3 | 0 | 0 | 3 | 10 | 3 | 3 | 144 | 11 | 121 | 39 | 103 | 12 | 57 | 25 | 53 | 10 | 1 | 2 | 15 |
11,590 | ray-project/ray | rllib/models/torch/mingpt.py | rllib.models.torch.mingpt.Block | import torch.nn as nn
from ray._common.deprecation import Deprecated
@Deprecated(error=False)
class Block(nn.Module):
"""an unassuming Transformer block"""
def __init__(self, config: GPTConfig):
super().__init__()
self.ln_1 = nn.LayerNorm(config.n_embed)
self.attn = CausalSelfAttention... | @Deprecated(error=False)
class Block(nn.Module):
'''an unassuming Transformer block'''
def __init__(self, config: GPTConfig):
pass
def forward(self, x, attention_masks=None):
pass | 4 | 1 | 12 | 1 | 10 | 2 | 1 | 0.25 | 1 | 5 | 3 | 0 | 2 | 4 | 2 | 12 | 28 | 3 | 20 | 9 | 17 | 5 | 13 | 9 | 10 | 1 | 1 | 0 | 2 |
11,591 | ray-project/ray | rllib/models/torch/mingpt.py | rllib.models.torch.mingpt.CausalSelfAttention | import torch
from torch.nn import functional as F
import math
import torch.nn as nn
from ray._common.deprecation import Deprecated
@Deprecated(error=False)
class CausalSelfAttention(nn.Module):
"""
Vanilla multi-head masked self-attention layer with a projection at the end.
It is possible to use torch.nn.M... | @Deprecated(error=False)
class CausalSelfAttention(nn.Module):
'''
Vanilla multi-head masked self-attention layer with a projection at the end.
It is possible to use torch.nn.MultiheadAttention here but I am including an
explicit implementation here to show that there is nothing too scary here.
'''
... | 4 | 1 | 25 | 2 | 16 | 8 | 2 | 0.66 | 1 | 3 | 1 | 0 | 2 | 6 | 2 | 12 | 57 | 5 | 32 | 13 | 29 | 21 | 27 | 13 | 24 | 2 | 1 | 1 | 3 |
11,592 | ray-project/ray | rllib/models/torch/mingpt.py | rllib.models.torch.mingpt.GPT | import math
import torch.nn as nn
from ray._common.deprecation import Deprecated
import torch
@Deprecated(error=False)
class GPT(nn.Module):
"""GPT Transformer Model"""
def __init__(self, config: GPTConfig):
super().__init__()
assert config.block_size is not None
self.block_size = conf... | @Deprecated(error=False)
class GPT(nn.Module):
'''GPT Transformer Model'''
def __init__(self, config: GPTConfig):
pass
def _init_weights(self, module):
pass
def forward(self, input_embeds, attention_masks=None, return_attentions=False):
'''
input_embeds: [batch_size x ... | 5 | 2 | 25 | 2 | 16 | 7 | 4 | 0.42 | 1 | 5 | 2 | 0 | 3 | 2 | 3 | 13 | 81 | 10 | 50 | 14 | 46 | 21 | 36 | 13 | 32 | 5 | 1 | 2 | 12 |
11,593 | ray-project/ray | rllib/models/torch/mingpt.py | rllib.models.torch.mingpt.GPTConfig | from dataclasses import dataclass
from ray.rllib.utils.annotations import DeveloperAPI
@DeveloperAPI
@dataclass
class GPTConfig:
block_size: int
n_layer: int = 12
n_head: int = 12
n_embed: int = 768
embed_pdrop: float = 0.1
resid_pdrop: float = 0.1
attn_pdrop: float = 0.1 | @DeveloperAPI
@dataclass
class GPTConfig:
pass | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0.38 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 2 | 8 | 7 | 7 | 3 | 8 | 7 | 7 | 0 | 0 | 0 | 0 |
11,594 | ray-project/ray | rllib/models/torch/mingpt.py | rllib.models.torch.mingpt.NewGELU | from ray._common.deprecation import Deprecated
import torch.nn as nn
import math
import torch
@Deprecated(error=False)
class NewGELU(nn.Module):
"""
Implementation of the GELU activation function currently in Google BERT
repo (identical to OpenAI GPT).
Reference: Gaussian Error Linear Units (GELU) pape... | @Deprecated(error=False)
class NewGELU(nn.Module):
'''
Implementation of the GELU activation function currently in Google BERT
repo (identical to OpenAI GPT).
Reference: Gaussian Error Linear Units (GELU) paper:
https://arxiv.org/abs/1606.08415
'''
def forward(self, x):
pass | 3 | 1 | 11 | 0 | 11 | 0 | 1 | 0.5 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 11 | 19 | 1 | 12 | 2 | 10 | 6 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
11,595 | ray-project/ray | rllib/models/torch/misc.py | rllib.models.torch.misc.AppendBiasLayer | from ray.rllib.utils.annotations import DeveloperAPI
from ray.rllib.utils.typing import TensorType
@DeveloperAPI
class AppendBiasLayer(nn.Module):
"""Simple bias appending layer for free_log_std."""
def __init__(self, num_bias_vars: int):
super().__init__()
self.log_std = torch.nn.Parameter(to... | @DeveloperAPI
class AppendBiasLayer(nn.Module):
'''Simple bias appending layer for free_log_std.'''
def __init__(self, num_bias_vars: int):
pass
def forward(self, x: TensorType) -> TensorType:
pass | 4 | 1 | 4 | 0 | 4 | 0 | 1 | 0.13 | 1 | 2 | 0 | 0 | 2 | 1 | 2 | 2 | 11 | 2 | 8 | 5 | 5 | 1 | 8 | 5 | 5 | 1 | 1 | 0 | 2 |
11,596 | ray-project/ray | rllib/models/torch/misc.py | rllib.models.torch.misc.Reshape | from typing import Union, Tuple, Any, List
from ray.rllib.utils.annotations import DeveloperAPI
@DeveloperAPI
class Reshape(nn.Module):
"""Standard module that reshapes/views a tensor"""
def __init__(self, shape: List):
super().__init__()
self.shape = shape
def forward(self, x):
r... | @DeveloperAPI
class Reshape(nn.Module):
'''Standard module that reshapes/views a tensor'''
def __init__(self, shape: List):
pass
def forward(self, x):
pass | 4 | 1 | 3 | 0 | 3 | 0 | 1 | 0.17 | 1 | 1 | 0 | 0 | 2 | 1 | 2 | 2 | 9 | 2 | 6 | 4 | 3 | 1 | 6 | 4 | 3 | 1 | 1 | 0 | 2 |
11,597 | ray-project/ray | rllib/models/torch/misc.py | rllib.models.torch.misc.SlimConv2d | from ray.rllib.utils.typing import TensorType
from ray.rllib.models.utils import get_activation_fn
from typing import Union, Tuple, Any, List
from ray.rllib.utils.annotations import DeveloperAPI
@DeveloperAPI
class SlimConv2d(nn.Module):
"""Simple mock of tf.slim Conv2d"""
def __init__(self, in_channels: int,... | @DeveloperAPI
class SlimConv2d(nn.Module):
'''Simple mock of tf.slim Conv2d'''
def __init__(self, in_channels: int, out_channels: int, kernel: Union[int, Tuple[int, int]], stride: Union[int, Tuple[int, int]], padding: Union[int, Tuple[int, int]], initializer: Any='default', activation_fn: Any='default', bias_i... | 4 | 2 | 27 | 1 | 16 | 10 | 4 | 0.64 | 1 | 5 | 0 | 0 | 2 | 1 | 2 | 2 | 57 | 3 | 33 | 16 | 20 | 21 | 22 | 6 | 19 | 7 | 1 | 2 | 8 |
11,598 | ray-project/ray | rllib/models/torch/misc.py | rllib.models.torch.misc.SlimFC | from ray.rllib.models.utils import get_activation_fn
from ray.rllib.utils.annotations import DeveloperAPI
from typing import Union, Tuple, Any, List
from ray.rllib.utils.typing import TensorType
@DeveloperAPI
class SlimFC(nn.Module):
"""Simple PyTorch version of `linear` function"""
def __init__(self, in_size... | @DeveloperAPI
class SlimFC(nn.Module):
'''Simple PyTorch version of `linear` function'''
def __init__(self, in_size: int, out_size: int, initializer: Any=None, activation_fn: Any=None, use_bias: bool=True, bias_init: float=0.0):
'''Creates a standard FC layer, similar to torch.nn.Linear
Args:
... | 4 | 2 | 19 | 1 | 13 | 6 | 3 | 0.5 | 1 | 6 | 0 | 0 | 2 | 1 | 2 | 2 | 42 | 3 | 26 | 14 | 15 | 13 | 18 | 6 | 15 | 5 | 1 | 1 | 6 |
11,599 | ray-project/ray | rllib/models/torch/modules/gru_gate.py | rllib.models.torch.modules.gru_gate.GRUGate | from ray.rllib.utils.annotations import OldAPIStack
from ray.rllib.utils.typing import TensorType
@OldAPIStack
class GRUGate(nn.Module):
"""Implements a gated recurrent unit for use in AttentionNet"""
def __init__(self, dim: int, init_bias: int=0.0, **kwargs):
"""
input_shape (torch.Tensor): d... | @OldAPIStack
class GRUGate(nn.Module):
'''Implements a gated recurrent unit for use in AttentionNet'''
def __init__(self, dim: int, init_bias: int=0.0, **kwargs):
'''
input_shape (torch.Tensor): dimension of the input
init_bias: Bias added to every input to stabilize training
''... | 4 | 2 | 28 | 3 | 22 | 3 | 1 | 0.16 | 1 | 2 | 0 | 0 | 2 | 7 | 2 | 2 | 59 | 8 | 44 | 14 | 41 | 7 | 32 | 14 | 29 | 1 | 1 | 0 | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.