Robotics
LeRobot
Safetensors
lehome-challenge
smolvla
residual-rl
v1tavitavita commited on
Commit
48588a8
·
verified ·
1 Parent(s): 421d85f

wrapper: module-level HF_HOME redirect to bundled cache

Browse files
Files changed (1) hide show
  1. residual_v4_global.py +35 -8
residual_v4_global.py CHANGED
@@ -16,16 +16,43 @@ Optional:
16
  from __future__ import annotations
17
 
18
  import os
 
19
  from pathlib import Path
20
- from typing import Dict, Optional
21
 
22
- import numpy as np
23
- import torch
24
- from torch import nn
25
-
26
- from .base_policy import BasePolicy
27
- from .lerobot_policy import LeRobotPolicy
28
- from .registry import PolicyRegistry
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  class _ResidualActor(nn.Module):
 
16
  from __future__ import annotations
17
 
18
  import os
19
+ import sys
20
  from pathlib import Path
 
21
 
22
+ # --- Module-level HF cache redirect (must run BEFORE transformers/huggingface_hub
23
+ # get imported transitively by lerobot_policy / smolvla). The evaluator commonly
24
+ # pre-sets HF_HOME to its own cache; we override unconditionally so the bundled
25
+ # SmolVLM2 weights at submission_models/hf_cache/ are used.
26
+ _backbone_env = os.environ.get("LEHOME_VLA_POLICY_PATH", "")
27
+ if _backbone_env:
28
+ _bundled_cache = Path(_backbone_env).parent / "hf_cache"
29
+ if _bundled_cache.exists():
30
+ os.environ["HF_HOME"] = str(_bundled_cache)
31
+ os.environ["TRANSFORMERS_CACHE"] = str(_bundled_cache / "hub")
32
+ os.environ["HF_HUB_CACHE"] = str(_bundled_cache / "hub")
33
+ # Also patch any already-imported huggingface_hub constants so cache
34
+ # lookups don't reuse stale values from a pre-import HF_HOME.
35
+ if "huggingface_hub.constants" in sys.modules:
36
+ _hc = sys.modules["huggingface_hub.constants"]
37
+ for _attr, _val in (
38
+ ("HF_HOME", str(_bundled_cache)),
39
+ ("HF_HUB_CACHE", str(_bundled_cache / "hub")),
40
+ ("HUGGINGFACE_HUB_CACHE", str(_bundled_cache / "hub")),
41
+ ):
42
+ if hasattr(_hc, _attr):
43
+ setattr(_hc, _attr, _val)
44
+ print(f"[residual_v4_global] HF_HOME -> {_bundled_cache}", flush=True)
45
+ # ----------------------------------------------------------------------------
46
+
47
+ from typing import Dict, Optional # noqa: E402
48
+
49
+ import numpy as np # noqa: E402
50
+ import torch # noqa: E402
51
+ from torch import nn # noqa: E402
52
+
53
+ from .base_policy import BasePolicy # noqa: E402
54
+ from .lerobot_policy import LeRobotPolicy # noqa: E402
55
+ from .registry import PolicyRegistry # noqa: E402
56
 
57
 
58
  class _ResidualActor(nn.Module):