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_cartpole_with_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 "obs_continuous": torch.zeros(B, S, 4, dtype=torch.float32),
9 },
10 batch_size=(B, S),
11)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 |
|---|---|---|
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 "obs_continuous": obs.unsqueeze(1).float(), # [B, 1, 4]
7 },
8 batch_size=(B, 1),
9 )
10
11 with torch.no_grad():
12 out, cache = model(step_stream.to(device), cache=cache, use_cache=True)
13 action = model.get_action(out, head="vec_dqn", temperature=0.0)
14 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.