Instructions to use ReasoningKingdom/LITOperator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LeRobot
How to use ReasoningKingdom/LITOperator with LeRobot:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download sandbox/lit_robot.py from ReasoningKingdom/LITOperator: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/ReasoningKingdom/LITOperator/resolve/main/sandbox/lit_robot.py
- Command line
-
hf download hf://ReasoningKingdom/LITOperator/sandbox/lit_robot.py
-
curl -L -o lit_robot.py https://huggingface.co/ReasoningKingdom/LITOperator/resolve/main/sandbox/lit_robot.py
2.18 kB
| #!/usr/bin/env python3 | |
| """lit_robot.py — the foolproof robot interface. | |
| from lit_robot import LITOperator | |
| op = LITOperator("weights/tree.safetensors", codec) | |
| actions = op(observation) # open-loop program: [action, ...] | |
| One observation in, the whole action path out. Inference is open-loop: | |
| the tree is searched once and the program is returned; the world is | |
| never stepped and never asked for feedback. `None` means the tree knows | |
| no goal path from this observation; no action is fabricated. | |
| The codec is the host's 16-hex glue (LeRobot features -> 64 u64 slots), | |
| supplied by the caller. The operator itself never interprets a robot, | |
| a camera, or an action. | |
| """ | |
| import os | |
| import sys | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| REPO = os.path.dirname(HERE) | |
| OP = os.path.join(REPO, "lit_operator") | |
| if OP not in sys.path: | |
| sys.path.insert(0, OP) | |
| from lit_world import LitWorld # noqa: E402 | |
| U64_MASK = (1 << 64) - 1 | |
| class ProgramWorld: | |
| """The only two host facts inference needs: key and decode.""" | |
| def __init__(self, codec): | |
| self.codec = codec | |
| def key(self, frame): | |
| words = self.codec.state_words(frame) | |
| return (self.codec.state_key(words), 0) | |
| def decode(self, act): | |
| code = (int(act.id) | (int(act.x) << 32)) & U64_MASK | |
| return self.codec.action_vec(code) | |
| class LITOperator: | |
| """Load a tree once; call it like a library.""" | |
| def __init__(self, tree, codec): | |
| self.codec = codec | |
| self.world = ProgramWorld(codec) | |
| self.model = LitWorld(self.world) | |
| self.session = self.model.load_tree(tree) | |
| def program(self, observation): | |
| """Observation -> the whole open-loop action path, or None.""" | |
| return self.model.program(observation) | |
| def program_key(self, key): | |
| """Same, when the host already has the 128-bit observation key.""" | |
| return self.model.program_key(key) | |
| __call__ = program | |
| def stats(self): | |
| return self.session.stats() | |
| def close(self): | |
| self.model.free() | |
| def __enter__(self): | |
| return self | |
| def __exit__(self, *exc): | |
| self.close() | |
| return False | |