Views
No views yet
pip install "git+https://github.com/micahr234/MOUSE.git"1from mouse.models.base import load_model
2
3model = load_model("micahr234/ns_gym_frozenlake_without_bb")
4model.eval()TensorDict[B, S] — B parallel sequences of S timesteps each.
This model was trained with S = 100; keep context close to that.1import torch
2from tensordict import TensorDict
3
4B, S = 1, 1 # S grows each step when using the cache
5
6step_stream = TensorDict(
7 {
8 "action": torch.zeros(B, S, dtype=torch.int64),
9 "reward": torch.zeros(B, S, dtype=torch.float32),
10 "done": torch.zeros(B, S, dtype=torch.int64), # 0=alive 1=terminal 2=truncated
11 "obs_discrete": torch.zeros(B, S, dtype=torch.int64),
12 },
13 batch_size=(B, S),
14)1device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
2
3with torch.no_grad():
4 out, cache = model(step_stream.to(device))out is a TensorDict[B, S] with one key per enabled head (A = model.max_num_actions, D = vec_dim):| Key | Shape | Description |
|---|---|---|
dqn | [B, S, A] | Q-value logits (online) |
dqn_target | [B, S, A] | Q-value logits (target) |
vec_dqn | [B, S, A, D] | Action vectors (online); use get_action or vec_dqn_scores |
vec_dqn_target | [B, S, A, D] | Action vectors (target) |
1# greedy (temperature=0) or stochastic (temperature>0)
2action = model.get_action(out, head="vec_dqn", temperature=0.0) # [B]S=1) and carry the cache forward to avoid
re-processing the full history on every call:1cache = None
2
3while not done:
4 step_stream = TensorDict(
5 {
6 "action": last_action.unsqueeze(1),
7 "reward": last_reward.unsqueeze(1),
8 "done": last_done.unsqueeze(1),
9 "obs_discrete": obs_disc.unsqueeze(1), # [B, 1]
10 },
11 batch_size=(B, 1),
12 )
13
14 with torch.no_grad():
15 out, cache = model(step_stream.to(device), cache=cache, use_cache=True)
16 action = model.get_action(out, head="vec_dqn", temperature=0.0)
17 step_idx += 1Cache warning. This model was trained on sequences of length 100. Quality degrades once the cache exceeds roughly 2× that length — reset it (cache = None) before that limit.