forked from MLShukai/ami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from MLShukai/myxy/lerp-stacked-hidden
隠れ状態の線形補間
- Loading branch information
Showing
6 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import torch.nn as nn | ||
from torch import Tensor | ||
|
||
|
||
class ResNetFF(nn.Module): | ||
def __init__(self, dim: int, dim_hidden: int, depth: int, activation: nn.Module = nn.ReLU()): | ||
super().__init__() | ||
self.ff_list = nn.ModuleList( | ||
[nn.Sequential(nn.Linear(dim, dim_hidden), activation, nn.Linear(dim_hidden, dim)) for _ in range(depth)] | ||
) | ||
|
||
def forward(self, x: Tensor) -> Tensor: | ||
for ff in self.ff_list: | ||
x_ = x | ||
x = ff(x) | ||
x = x + x_ | ||
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# @package _global_ | ||
|
||
defaults: | ||
- world_models_sioconv | ||
- override /models: world_models_sioconv_lerp_hidden | ||
|
||
task_name: world_models_sioconv_lerp_hidden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
image_encoder: | ||
_target_: ami.models.vae.EncoderWrapper | ||
default_device: ${devices.0} | ||
has_inference: True | ||
model: | ||
_target_: ami.models.vae.Conv2dEncoder | ||
height: ${shared.image_height} | ||
width: ${shared.image_width} | ||
channels: ${shared.image_channels} | ||
latent_dim: 512 # From primitive AMI. | ||
do_batchnorm: True | ||
|
||
image_decoder: | ||
_target_: ami.models.model_wrapper.ModelWrapper | ||
default_device: ${devices.0} | ||
has_inference: False | ||
model: | ||
_target_: ami.models.vae.Conv2dDecoder | ||
height: ${models.image_encoder.model.height} | ||
width: ${models.image_encoder.model.width} | ||
channels: ${models.image_encoder.model.channels} | ||
latent_dim: ${models.image_encoder.model.latent_dim} | ||
do_batchnorm: True | ||
|
||
forward_dynamics: | ||
_target_: ami.models.model_wrapper.ModelWrapper | ||
default_device: ${devices.0} | ||
has_inference: True | ||
model: | ||
_target_: ami.models.forward_dynamics.ForwardDynamics | ||
observation_flatten: | ||
_target_: torch.nn.Identity | ||
action_flatten: | ||
_target_: ami.models.components.multi_embeddings.MultiEmbeddings | ||
choices_per_category: | ||
_target_: hydra.utils.get_object | ||
path: ami.interactions.environments.actuators.vrchat_osc_discrete_actuator.ACTION_CHOICES_PER_CATEGORY | ||
embedding_dim: 8 | ||
do_flatten: True | ||
obs_action_projection: | ||
_target_: torch.nn.Linear | ||
# action_embedding_dim * num_action_choices + obs_embedding_dim | ||
in_features: ${python.eval:"${..action_flatten.embedding_dim} * 5 + ${models.image_encoder.model.latent_dim}"} | ||
out_features: ${..core_model.dim} | ||
core_model: | ||
_target_: ami.models.components.sioconv.SioConv | ||
depth: 8 | ||
dim: 512 | ||
num_head: 8 | ||
dim_ff_hidden: 512 | ||
chunk_size: 512 | ||
dropout: 0.1 | ||
obs_hat_dist_head: | ||
_target_: ami.models.components.fully_connected_fixed_std_normal.FullyConnectedFixedStdNormal | ||
dim_in: ${..core_model.dim} | ||
dim_out: ${models.image_encoder.model.latent_dim} | ||
normal_cls: | ||
_target_: hydra.utils.get_class | ||
path: ami.models.components.fully_connected_fixed_std_normal.DeterministicNormal | ||
|
||
policy_value: | ||
_target_: ami.models.model_wrapper.ModelWrapper | ||
default_device: ${devices.0} | ||
has_inference: True | ||
model: | ||
_target_: ami.models.policy_value_common_net.PolicyValueCommonNet | ||
observation_projection: | ||
_target_: torch.nn.Linear | ||
in_features: ${models.image_encoder.model.latent_dim} | ||
out_features: 512 | ||
forward_dynamics_hidden_projection: | ||
_target_: ami.models.policy_value_common_net.LerpStackedHidden | ||
dim: ${models.forward_dynamics.model.core_model.dim} | ||
depth: ${models.forward_dynamics.model.core_model.depth} | ||
num_head: ${models.forward_dynamics.model.core_model.num_head} | ||
observation_hidden_projection: | ||
_target_: ami.models.policy_value_common_net.ConcatFlattenedObservationAndLerpedHidden | ||
dim_obs: ${..observation_projection.out_features} | ||
dim_hidden: ${models.forward_dynamics.model.core_model.dim} | ||
dim_out: 512 | ||
core_model: | ||
_target_: ami.models.components.resnet.ResNetFF | ||
dim: ${..observation_hidden_projection.dim_out} | ||
dim_hidden: 1024 | ||
depth: 4 | ||
policy_head: | ||
_target_: ami.models.components.discrete_policy_head.DiscretePolicyHead | ||
dim_in: ${..observation_hidden_projection.dim_out} | ||
action_choices_per_category: | ||
_target_: hydra.utils.get_object | ||
path: ami.interactions.environments.actuators.vrchat_osc_discrete_actuator.ACTION_CHOICES_PER_CATEGORY | ||
value_head: | ||
_target_: ami.models.components.fully_connected_value_head.FullyConnectedValueHead | ||
dim_in: ${..observation_hidden_projection.dim_out} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
import torch | ||
|
||
from ami.models.components.resnet import ResNetFF | ||
|
||
|
||
class TestResNetFF: | ||
@pytest.mark.parametrize( | ||
""" | ||
batch, | ||
dim, | ||
dim_hidden, | ||
depth, | ||
""", | ||
[ | ||
(3, 128, 256, 4), | ||
(6, 28, 56, 2), | ||
], | ||
) | ||
def test_resnet_ff(self, batch, dim, dim_hidden, depth): | ||
mod = ResNetFF(dim, dim_hidden, depth) | ||
x = torch.randn(batch, dim) | ||
x = mod(x) | ||
assert x.shape == (batch, dim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters