worldkernels 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- worldkernels/__init__.py +35 -0
- worldkernels/_version.py +3 -0
- worldkernels/cli/main.py +44 -0
- worldkernels/core/__init__.py +0 -0
- worldkernels/core/action.py +34 -0
- worldkernels/core/config.py +42 -0
- worldkernels/core/engine.py +113 -0
- worldkernels/core/observation.py +39 -0
- worldkernels/core/session.py +95 -0
- worldkernels/integrations/__init__.py +0 -0
- worldkernels/integrations/comfyui.py +0 -0
- worldkernels/runtime/__init__.py +0 -0
- worldkernels/runtime/backends/__init__.py +0 -0
- worldkernels/runtime/backends/compile.py +0 -0
- worldkernels/runtime/backends/eager.py +0 -0
- worldkernels/runtime/backends/tensorrt.py +0 -0
- worldkernels/runtime/executor.py +0 -0
- worldkernels/runtime/memory.py +0 -0
- worldkernels/runtime/scheduler.py +0 -0
- worldkernels/serving/__init__.py +0 -0
- worldkernels/serving/auth.py +0 -0
- worldkernels/serving/routes.py +0 -0
- worldkernels/serving/server.py +0 -0
- worldkernels/serving/websocket.py +0 -0
- worldkernels/worlds/__init__.py +0 -0
- worldkernels/worlds/adapters/__init__.py +0 -0
- worldkernels/worlds/adapters/diffusers.py +0 -0
- worldkernels/worlds/base.py +0 -0
- worldkernels/worlds/registry.py +0 -0
- worldkernels-0.1.0.dist-info/METADATA +624 -0
- worldkernels-0.1.0.dist-info/RECORD +35 -0
- worldkernels-0.1.0.dist-info/WHEEL +5 -0
- worldkernels-0.1.0.dist-info/entry_points.txt +2 -0
- worldkernels-0.1.0.dist-info/licenses/LICENSE +504 -0
- worldkernels-0.1.0.dist-info/top_level.txt +1 -0
worldkernels/__init__.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WorldKernels - GPU-first world model simulation engine.
|
|
3
|
+
|
|
4
|
+
Serve learned world models (DiT, VAE) as interactive sessions.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
>>> from worldkernels import WorldKernel, Action, WorldConfig
|
|
8
|
+
>>> wk = WorldKernel(device="cuda")
|
|
9
|
+
>>> wk.load_world("Etched/oasis-500m")
|
|
10
|
+
>>> session = wk.create_session(world="oasis-500m", config=WorldConfig())
|
|
11
|
+
>>> obs = session.step(Action("keyboard", {"keys": ["W"]}))
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from worldkernels.core.action import Action
|
|
15
|
+
from worldkernels.core.config import ServerConfig, WorldConfig
|
|
16
|
+
from worldkernels.core.engine import WorldKernel
|
|
17
|
+
from worldkernels.core.observation import Observation
|
|
18
|
+
from worldkernels.core.session import Session, SessionStatus
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from worldkernels._version import __version__, __version_tuple__
|
|
22
|
+
except ImportError:
|
|
23
|
+
__version__ = "0.1.0.dev0"
|
|
24
|
+
__version_tuple__ = (0, 1, 0, "dev0")
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"WorldKernel",
|
|
28
|
+
"Session",
|
|
29
|
+
"SessionStatus",
|
|
30
|
+
"Action",
|
|
31
|
+
"Observation",
|
|
32
|
+
"WorldConfig",
|
|
33
|
+
"ServerConfig",
|
|
34
|
+
"__version__",
|
|
35
|
+
]
|
worldkernels/_version.py
ADDED
worldkernels/cli/main.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""WorldKernels CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def app() -> None:
|
|
9
|
+
"""Main CLI entry point."""
|
|
10
|
+
args = sys.argv[1:]
|
|
11
|
+
|
|
12
|
+
if not args or args[0] in ("-h", "--help", "help"):
|
|
13
|
+
print(
|
|
14
|
+
"""worldkernels - GPU-first world model simulation engine
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
worldkernels serve [--host HOST] [--port PORT] Start HTTP/WebSocket server
|
|
18
|
+
worldkernels version Show version
|
|
19
|
+
worldkernels --help Show this help
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
worldkernels serve --host 0.0.0.0 --port 8000
|
|
23
|
+
"""
|
|
24
|
+
)
|
|
25
|
+
return
|
|
26
|
+
|
|
27
|
+
if args[0] in ("version", "--version", "-V"):
|
|
28
|
+
from worldkernels import __version__
|
|
29
|
+
|
|
30
|
+
print(f"worldkernels {__version__}")
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
if args[0] == "serve":
|
|
34
|
+
print("Server not yet implemented. Coming soon!")
|
|
35
|
+
print("Install with: pip install worldkernels[serve]")
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
print(f"Unknown command: {args[0]}")
|
|
39
|
+
print("Run 'worldkernels --help' for usage.")
|
|
40
|
+
sys.exit(1)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
app()
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Action schema for world model inputs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Action:
|
|
11
|
+
"""
|
|
12
|
+
Generalized action container.
|
|
13
|
+
|
|
14
|
+
Not RL-specific — just "control input to world".
|
|
15
|
+
|
|
16
|
+
Examples:
|
|
17
|
+
>>> Action("keyboard", {"keys": ["W", "SPACE"]})
|
|
18
|
+
>>> Action("continuous", {"velocity": [0.1, 0.0, 0.5]})
|
|
19
|
+
>>> Action("camera", {"trajectory": "orbit_left_30"})
|
|
20
|
+
>>> Action("text", {"command": "open the door"})
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
action_type: str
|
|
24
|
+
"""Type of action, e.g., 'keyboard', 'continuous', 'text', 'pose'."""
|
|
25
|
+
|
|
26
|
+
payload: dict[str, Any] = field(default_factory=dict)
|
|
27
|
+
"""Schema depends on action_type."""
|
|
28
|
+
|
|
29
|
+
timestamp: float | None = None
|
|
30
|
+
"""Optional timing information."""
|
|
31
|
+
|
|
32
|
+
def __post_init__(self) -> None:
|
|
33
|
+
if not self.action_type:
|
|
34
|
+
raise ValueError("action_type cannot be empty")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Configuration dataclasses for WorldKernel."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class WorldConfig:
|
|
11
|
+
"""Per-session generation parameters."""
|
|
12
|
+
|
|
13
|
+
# Resolution / format
|
|
14
|
+
height: int = 480
|
|
15
|
+
width: int = 848
|
|
16
|
+
fps: int = 24
|
|
17
|
+
|
|
18
|
+
# Generation quality
|
|
19
|
+
num_inference_steps: int = 4
|
|
20
|
+
guidance_scale: float = 1.0
|
|
21
|
+
|
|
22
|
+
# Chunking (how many frames per step call)
|
|
23
|
+
frames_per_step: int = 8
|
|
24
|
+
|
|
25
|
+
# Conditioning
|
|
26
|
+
initial_prompt: str | None = None
|
|
27
|
+
initial_image: str | None = None # path or base64
|
|
28
|
+
|
|
29
|
+
# Compute budget
|
|
30
|
+
max_vram_gb: float | None = None
|
|
31
|
+
precision: Literal["bf16", "fp16", "fp32"] = "bf16"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ServerConfig:
|
|
36
|
+
"""Configuration for the HTTP/WebSocket server."""
|
|
37
|
+
|
|
38
|
+
host: str = "0.0.0.0"
|
|
39
|
+
port: int = 8000
|
|
40
|
+
max_sessions: int = 4
|
|
41
|
+
api_key: str | None = None
|
|
42
|
+
cors_origins: list[str] = field(default_factory=lambda: ["*"])
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""WorldKernel main engine class."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from worldkernels.core.config import WorldConfig
|
|
9
|
+
from worldkernels.core.session import Session
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WorldKernel:
|
|
13
|
+
"""
|
|
14
|
+
GPU-first world model simulation engine.
|
|
15
|
+
|
|
16
|
+
This is the main entry point for the WorldKernels library.
|
|
17
|
+
It manages world model loading, session creation, and resource lifecycle.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
>>> from worldkernels import WorldKernel, WorldConfig
|
|
21
|
+
>>> wk = WorldKernel(device="cuda")
|
|
22
|
+
>>> wk.load_world("Etched/oasis-500m")
|
|
23
|
+
>>> session = wk.create_session(world="oasis-500m", config=WorldConfig())
|
|
24
|
+
>>> obs = session.step(Action("keyboard", {"keys": ["W"]}))
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
device: str = "cuda",
|
|
30
|
+
max_sessions: int = 4,
|
|
31
|
+
offload_idle: bool = True,
|
|
32
|
+
) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Initialize the WorldKernel engine.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
device: Device to run on ('cuda', 'cuda:0', 'cpu').
|
|
38
|
+
max_sessions: Maximum concurrent sessions.
|
|
39
|
+
offload_idle: Whether to offload paused sessions to CPU.
|
|
40
|
+
"""
|
|
41
|
+
self.device = device
|
|
42
|
+
self.max_sessions = max_sessions
|
|
43
|
+
self.offload_idle = offload_idle
|
|
44
|
+
self._worlds: dict[str, object] = {}
|
|
45
|
+
self._sessions: dict[str, Session] = {}
|
|
46
|
+
|
|
47
|
+
def load_world(
|
|
48
|
+
self,
|
|
49
|
+
model_id: str,
|
|
50
|
+
alias: str | None = None,
|
|
51
|
+
trust_remote_code: bool = False,
|
|
52
|
+
) -> None:
|
|
53
|
+
"""
|
|
54
|
+
Load a world model from HuggingFace Hub or local path.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
model_id: HuggingFace model ID (e.g., 'Etched/oasis-500m') or local path.
|
|
58
|
+
alias: Optional alias for referencing this world.
|
|
59
|
+
trust_remote_code: Whether to trust remote code from the model repo.
|
|
60
|
+
"""
|
|
61
|
+
# Stub implementation
|
|
62
|
+
key = alias or model_id.split("/")[-1]
|
|
63
|
+
self._worlds[key] = {"model_id": model_id, "loaded": False}
|
|
64
|
+
|
|
65
|
+
def create_session(
|
|
66
|
+
self,
|
|
67
|
+
world: str,
|
|
68
|
+
config: WorldConfig | None = None,
|
|
69
|
+
seed: int | None = None,
|
|
70
|
+
) -> Session:
|
|
71
|
+
"""
|
|
72
|
+
Create a new simulation session.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
world: Name/alias of the loaded world model.
|
|
76
|
+
config: Session configuration.
|
|
77
|
+
seed: Random seed for reproducibility.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
A new Session instance.
|
|
81
|
+
"""
|
|
82
|
+
from worldkernels.core.config import WorldConfig as WC
|
|
83
|
+
from worldkernels.core.session import Session
|
|
84
|
+
|
|
85
|
+
if world not in self._worlds:
|
|
86
|
+
raise ValueError(f"World '{world}' not loaded. Call load_world() first.")
|
|
87
|
+
|
|
88
|
+
if len(self._sessions) >= self.max_sessions:
|
|
89
|
+
raise RuntimeError(f"Max sessions ({self.max_sessions}) reached.")
|
|
90
|
+
|
|
91
|
+
cfg = config or WC()
|
|
92
|
+
session = Session(world_id=world, config=cfg, seed=seed or 0)
|
|
93
|
+
self._sessions[session.session_id] = session
|
|
94
|
+
return session
|
|
95
|
+
|
|
96
|
+
def get_session(self, session_id: str) -> Session | None:
|
|
97
|
+
"""Get a session by ID."""
|
|
98
|
+
return self._sessions.get(session_id)
|
|
99
|
+
|
|
100
|
+
def list_sessions(self) -> list[str]:
|
|
101
|
+
"""List all active session IDs."""
|
|
102
|
+
return list(self._sessions.keys())
|
|
103
|
+
|
|
104
|
+
def list_worlds(self) -> list[str]:
|
|
105
|
+
"""List all loaded world model aliases."""
|
|
106
|
+
return list(self._worlds.keys())
|
|
107
|
+
|
|
108
|
+
def shutdown(self) -> None:
|
|
109
|
+
"""Cleanup all sessions and resources."""
|
|
110
|
+
for session in self._sessions.values():
|
|
111
|
+
session.close()
|
|
112
|
+
self._sessions.clear()
|
|
113
|
+
self._worlds.clear()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Observation types returned by world models."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Observation:
|
|
11
|
+
"""
|
|
12
|
+
Multi-modal observation output from a world model step.
|
|
13
|
+
|
|
14
|
+
This is NOT RL-specific (no reward/done by default).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
step_index: int
|
|
18
|
+
"""Which step this observation corresponds to."""
|
|
19
|
+
|
|
20
|
+
generation_time_ms: float
|
|
21
|
+
"""Time taken to generate this observation."""
|
|
22
|
+
|
|
23
|
+
frames: list[bytes] | None = None
|
|
24
|
+
"""RGB video frames (encoded or raw numpy bytes)."""
|
|
25
|
+
|
|
26
|
+
latent: bytes | None = None
|
|
27
|
+
"""Optional: return latent state for chaining."""
|
|
28
|
+
|
|
29
|
+
audio: bytes | None = None
|
|
30
|
+
"""Optional: audio track."""
|
|
31
|
+
|
|
32
|
+
depth: bytes | None = None
|
|
33
|
+
"""Optional: depth map."""
|
|
34
|
+
|
|
35
|
+
segmentation: bytes | None = None
|
|
36
|
+
"""Optional: semantic segmentation."""
|
|
37
|
+
|
|
38
|
+
structured: dict[str, Any] | None = field(default_factory=dict)
|
|
39
|
+
"""Optional: structured state (positions, velocities, etc.)."""
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Session lifecycle management."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import uuid
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from typing import TYPE_CHECKING, Any
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from worldkernels.core.action import Action
|
|
13
|
+
from worldkernels.core.config import WorldConfig
|
|
14
|
+
from worldkernels.core.observation import Observation
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SessionStatus(str, Enum):
|
|
18
|
+
"""Lifecycle status of a session."""
|
|
19
|
+
|
|
20
|
+
ACTIVE = "active"
|
|
21
|
+
PAUSED = "paused"
|
|
22
|
+
TERMINATED = "terminated"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class LatentState:
|
|
27
|
+
"""Opaque tensor bundle representing the current world state."""
|
|
28
|
+
|
|
29
|
+
data: Any = None # Will hold GPU tensors when implemented
|
|
30
|
+
device: str = "cpu"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class Session:
|
|
35
|
+
"""
|
|
36
|
+
A stateful simulation session.
|
|
37
|
+
|
|
38
|
+
Represents an interactive connection to a running world model.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
session_id: str = field(default_factory=lambda: f"sess_{uuid.uuid4().hex[:12]}")
|
|
42
|
+
"""Unique identifier for this session."""
|
|
43
|
+
|
|
44
|
+
world_id: str = ""
|
|
45
|
+
"""Which world model this session uses (registry key)."""
|
|
46
|
+
|
|
47
|
+
config: WorldConfig | None = None
|
|
48
|
+
"""Session configuration (resolution, fps, etc.)."""
|
|
49
|
+
|
|
50
|
+
# Latent state (kept on GPU or offloaded)
|
|
51
|
+
state: LatentState = field(default_factory=LatentState)
|
|
52
|
+
"""Current latent state of the simulation."""
|
|
53
|
+
|
|
54
|
+
step_index: int = 0
|
|
55
|
+
"""How many steps have been taken."""
|
|
56
|
+
|
|
57
|
+
# Provenance
|
|
58
|
+
seed: int = 0
|
|
59
|
+
action_history: list[Action] = field(default_factory=list)
|
|
60
|
+
"""History of actions for replay/debug."""
|
|
61
|
+
|
|
62
|
+
parent_session_id: str | None = None
|
|
63
|
+
"""If this session was branched from another."""
|
|
64
|
+
|
|
65
|
+
# Lifecycle
|
|
66
|
+
created_at: datetime = field(default_factory=datetime.now)
|
|
67
|
+
last_active_at: datetime = field(default_factory=datetime.now)
|
|
68
|
+
status: SessionStatus = SessionStatus.ACTIVE
|
|
69
|
+
|
|
70
|
+
# --- Methods (stubs for now) ---
|
|
71
|
+
|
|
72
|
+
def step(self, action: Action) -> Observation:
|
|
73
|
+
"""Execute one step with the given action."""
|
|
74
|
+
raise NotImplementedError("Session.step() not yet implemented")
|
|
75
|
+
|
|
76
|
+
def checkpoint(self) -> str:
|
|
77
|
+
"""Save current state, return checkpoint ID."""
|
|
78
|
+
raise NotImplementedError("Session.checkpoint() not yet implemented")
|
|
79
|
+
|
|
80
|
+
def restore(self, checkpoint_id: str) -> None:
|
|
81
|
+
"""Restore session to a saved checkpoint."""
|
|
82
|
+
raise NotImplementedError("Session.restore() not yet implemented")
|
|
83
|
+
|
|
84
|
+
def branch(self) -> Session:
|
|
85
|
+
"""Clone this session's state into a new session."""
|
|
86
|
+
raise NotImplementedError("Session.branch() not yet implemented")
|
|
87
|
+
|
|
88
|
+
def close(self) -> None:
|
|
89
|
+
"""Terminate this session and release resources."""
|
|
90
|
+
self.status = SessionStatus.TERMINATED
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def id(self) -> str:
|
|
94
|
+
"""Alias for session_id."""
|
|
95
|
+
return self.session_id
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|