Spaces:
Sleeping
Sleeping
Jean-baptiste Aujogue
commited on
Docker (#4)
Browse files* update torch management
* gitignore notebooks
* add dockerfile & dockerignore
* add HF Space metadata in readme
- .dockerignore +11 -0
- .gitignore +1 -0
- Dockerfile +43 -0
- README.md +18 -2
- notebooks/dev.ipynb +0 -138
- pyproject.toml +28 -4
- src/rubik/interface/app.py +2 -2
- uv.lock +0 -0
.dockerignore
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.coverage
|
2 |
+
.env
|
3 |
+
.mypy_cache
|
4 |
+
.pytest_cache
|
5 |
+
.ruff_cache
|
6 |
+
.venv
|
7 |
+
.vscode
|
8 |
+
|
9 |
+
*egg-info
|
10 |
+
|
11 |
+
notebooks
|
.gitignore
CHANGED
@@ -10,3 +10,4 @@
|
|
10 |
*egg-info
|
11 |
|
12 |
__pycache__
|
|
|
|
10 |
*egg-info
|
11 |
|
12 |
__pycache__
|
13 |
+
notebooks
|
Dockerfile
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
FROM python:3.11-slim-bookworm AS base
|
3 |
+
|
4 |
+
# --- Build stage ---
|
5 |
+
|
6 |
+
FROM base AS builder
|
7 |
+
|
8 |
+
COPY --from=ghcr.io/astral-sh/uv:0.8.3 / uv / uvx / bin/
|
9 |
+
|
10 |
+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
|
11 |
+
|
12 |
+
WORKDIR /app
|
13 |
+
|
14 |
+
COPY uv.lock pyproject.toml /app/
|
15 |
+
|
16 |
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
17 |
+
uv sync \
|
18 |
+
--frozen \
|
19 |
+
--extra torch-cpu \
|
20 |
+
--no-dev \
|
21 |
+
--no-install-project
|
22 |
+
|
23 |
+
COPY . /app
|
24 |
+
|
25 |
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
26 |
+
uv sync \
|
27 |
+
--frozen \
|
28 |
+
--extra torch-cpu \
|
29 |
+
--no-dev
|
30 |
+
|
31 |
+
# --- Final stage ---
|
32 |
+
|
33 |
+
FROM base AS final
|
34 |
+
|
35 |
+
COPY --from=builder /app /app
|
36 |
+
|
37 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
38 |
+
|
39 |
+
EXPOSE 7860
|
40 |
+
|
41 |
+
ENTRYPOINT [ "python", "-m", "rubik", "interface" ]
|
42 |
+
|
43 |
+
CMD []
|
README.md
CHANGED
@@ -1,16 +1,32 @@
|
|
1 |
# Rubik-Tensor
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
## Setup
|
5 |
|
6 |
-
This project uses `uv 0.
|
7 |
|
8 |
```shell
|
9 |
uv venv
|
10 |
(Activate env)
|
11 |
-
uv sync
|
12 |
pre-commit install
|
13 |
```
|
|
|
|
|
|
|
|
|
14 |
|
15 |
## Usage
|
16 |
|
|
|
1 |
# Rubik-Tensor
|
2 |
|
3 |
+
---
|
4 |
+
title: Rubik Tensor
|
5 |
+
emoji: ⚡
|
6 |
+
colorFrom: blue
|
7 |
+
colorTo: blue
|
8 |
+
sdk: docker
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: Interface for playing with Rubik cubes of any size
|
12 |
+
---
|
13 |
+
|
14 |
+
See the HF Space [JBAujogue/Rubik-Tensor](https://huggingface.co/spaces/JBAujogue/Rubik-Tensor)
|
15 |
|
16 |
## Setup
|
17 |
|
18 |
+
This project uses `uv 0.8.3` as environment & dependency manager, and `python 3.11` as core interpreter. Install the project with
|
19 |
|
20 |
```shell
|
21 |
uv venv
|
22 |
(Activate env)
|
23 |
+
uv sync --extra [extra]
|
24 |
pre-commit install
|
25 |
```
|
26 |
+
where `extra` should be one of the following:
|
27 |
+
- `torch`: pytorch package released on pypi (cpu-only form non-linux systems, cuda-enabled for linux systems).
|
28 |
+
- `torch-cpu`: cpu-only torch wheel.
|
29 |
+
- `torch-cu126`: cuda 12.6-compatible torch wheel.
|
30 |
|
31 |
## Usage
|
32 |
|
notebooks/dev.ipynb
DELETED
@@ -1,138 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": null,
|
6 |
-
"id": "0",
|
7 |
-
"metadata": {},
|
8 |
-
"outputs": [],
|
9 |
-
"source": [
|
10 |
-
"%load_ext autoreload\n",
|
11 |
-
"%autoreload 2"
|
12 |
-
]
|
13 |
-
},
|
14 |
-
{
|
15 |
-
"cell_type": "code",
|
16 |
-
"execution_count": null,
|
17 |
-
"id": "1",
|
18 |
-
"metadata": {},
|
19 |
-
"outputs": [],
|
20 |
-
"source": [
|
21 |
-
"import copy\n",
|
22 |
-
"\n",
|
23 |
-
"import torch"
|
24 |
-
]
|
25 |
-
},
|
26 |
-
{
|
27 |
-
"cell_type": "code",
|
28 |
-
"execution_count": null,
|
29 |
-
"id": "2",
|
30 |
-
"metadata": {},
|
31 |
-
"outputs": [],
|
32 |
-
"source": [
|
33 |
-
"from rubik.cube import Cube\n",
|
34 |
-
"from rubik.action import build_actions_tensor\n",
|
35 |
-
"from rubik.interface.plot import CubeVisualizer"
|
36 |
-
]
|
37 |
-
},
|
38 |
-
{
|
39 |
-
"cell_type": "code",
|
40 |
-
"execution_count": null,
|
41 |
-
"id": "3",
|
42 |
-
"metadata": {},
|
43 |
-
"outputs": [],
|
44 |
-
"source": [
|
45 |
-
"size = 3\n",
|
46 |
-
"\n",
|
47 |
-
"cube = Cube(size)\n",
|
48 |
-
"print(cube)"
|
49 |
-
]
|
50 |
-
},
|
51 |
-
{
|
52 |
-
"cell_type": "code",
|
53 |
-
"execution_count": null,
|
54 |
-
"id": "4",
|
55 |
-
"metadata": {},
|
56 |
-
"outputs": [],
|
57 |
-
"source": [
|
58 |
-
"cubis = copy.deepcopy(cube)\n",
|
59 |
-
"cubis.rotate(\"X2 X1i Y1i Z1i Y0 Z0i X2 X1i Y1i Z1i Y0 Z0i \")\n",
|
60 |
-
"\n",
|
61 |
-
"print(cubis)\n",
|
62 |
-
"print(cubis.history)"
|
63 |
-
]
|
64 |
-
},
|
65 |
-
{
|
66 |
-
"cell_type": "code",
|
67 |
-
"execution_count": null,
|
68 |
-
"id": "5",
|
69 |
-
"metadata": {},
|
70 |
-
"outputs": [],
|
71 |
-
"source": [
|
72 |
-
"visualizer = CubeVisualizer(size=cubis.size)\n",
|
73 |
-
"layout_args = {\"autosize\": False, \"width\": 600, \"height\": 600}\n",
|
74 |
-
"\n",
|
75 |
-
"visualizer(cubis.coordinates, cubis.state, cubis.size).update_layout(**layout_args).show()"
|
76 |
-
]
|
77 |
-
},
|
78 |
-
{
|
79 |
-
"cell_type": "code",
|
80 |
-
"execution_count": null,
|
81 |
-
"id": "6",
|
82 |
-
"metadata": {},
|
83 |
-
"outputs": [],
|
84 |
-
"source": [
|
85 |
-
"cubis = copy.deepcopy(cube)\n",
|
86 |
-
"cubis.scramble(20000, seed=0)\n",
|
87 |
-
"print(cubis)\n",
|
88 |
-
"print(cubis.history)"
|
89 |
-
]
|
90 |
-
},
|
91 |
-
{
|
92 |
-
"cell_type": "code",
|
93 |
-
"execution_count": null,
|
94 |
-
"id": "7",
|
95 |
-
"metadata": {},
|
96 |
-
"outputs": [],
|
97 |
-
"source": [
|
98 |
-
"cubis = copy.deepcopy(cube)\n",
|
99 |
-
"cubis.rotate(\"X2 X1i Y1i Z1i Y0 Z0i X2 X1i Y1i Z1i Y0 Z0i \" * 1000)\n",
|
100 |
-
"print(cubis)\n",
|
101 |
-
"print(cubis.history)"
|
102 |
-
]
|
103 |
-
},
|
104 |
-
{
|
105 |
-
"cell_type": "code",
|
106 |
-
"execution_count": null,
|
107 |
-
"id": "8",
|
108 |
-
"metadata": {},
|
109 |
-
"outputs": [],
|
110 |
-
"source": [
|
111 |
-
"actions = build_actions_tensor(size)\n",
|
112 |
-
"\n",
|
113 |
-
"torch.gather(actions[0, 2, 0], 0, actions[0, 1, 1])"
|
114 |
-
]
|
115 |
-
}
|
116 |
-
],
|
117 |
-
"metadata": {
|
118 |
-
"kernelspec": {
|
119 |
-
"display_name": "Rubik-Tensor",
|
120 |
-
"language": "python",
|
121 |
-
"name": "python3"
|
122 |
-
},
|
123 |
-
"language_info": {
|
124 |
-
"codemirror_mode": {
|
125 |
-
"name": "ipython",
|
126 |
-
"version": 3
|
127 |
-
},
|
128 |
-
"file_extension": ".py",
|
129 |
-
"mimetype": "text/x-python",
|
130 |
-
"name": "python",
|
131 |
-
"nbconvert_exporter": "python",
|
132 |
-
"pygments_lexer": "ipython3",
|
133 |
-
"version": "3.11.13"
|
134 |
-
}
|
135 |
-
},
|
136 |
-
"nbformat": 4,
|
137 |
-
"nbformat_minor": 5
|
138 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pyproject.toml
CHANGED
@@ -3,16 +3,19 @@ name = "rubik-tensor"
|
|
3 |
version = "0.1.0"
|
4 |
description = "Add your description here"
|
5 |
readme = "README.md"
|
6 |
-
requires-python = ">=3.11,<3.
|
7 |
dependencies = [
|
8 |
"fire>=0.7.0",
|
9 |
"gradio>=5.38",
|
10 |
"loguru>=0.7.3",
|
11 |
"plotly>=6.2.0",
|
12 |
-
"pydantic>=2.11.7",
|
13 |
-
"torch>=2.7.1",
|
14 |
]
|
15 |
|
|
|
|
|
|
|
|
|
|
|
16 |
[dependency-groups]
|
17 |
dev = [
|
18 |
"jupyter>=1.1.1",
|
@@ -25,13 +28,34 @@ dev = [
|
|
25 |
|
26 |
[tool.uv]
|
27 |
package = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
[tool.uv.sources]
|
30 |
-
torch =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
[[tool.uv.index]]
|
33 |
name = "torch-cu126"
|
34 |
url = "https://download.pytorch.org/whl/cu126"
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
[tool.ruff]
|
37 |
line-length = 120
|
|
|
3 |
version = "0.1.0"
|
4 |
description = "Add your description here"
|
5 |
readme = "README.md"
|
6 |
+
requires-python = ">=3.11,<3.14"
|
7 |
dependencies = [
|
8 |
"fire>=0.7.0",
|
9 |
"gradio>=5.38",
|
10 |
"loguru>=0.7.3",
|
11 |
"plotly>=6.2.0",
|
|
|
|
|
12 |
]
|
13 |
|
14 |
+
[project.optional-dependencies]
|
15 |
+
torch = [ "torch>=2.7.1" ]
|
16 |
+
torch-cpu = [ "torch>=2.7.1" ]
|
17 |
+
torch-cu126 = [ "torch>=2.7.1" ]
|
18 |
+
|
19 |
[dependency-groups]
|
20 |
dev = [
|
21 |
"jupyter>=1.1.1",
|
|
|
28 |
|
29 |
[tool.uv]
|
30 |
package = true
|
31 |
+
conflicts = [
|
32 |
+
[
|
33 |
+
{ extra = "torch" },
|
34 |
+
{ extra = "torch-cpu" },
|
35 |
+
{ extra = "torch-cu126" },
|
36 |
+
],
|
37 |
+
]
|
38 |
|
39 |
[tool.uv.sources]
|
40 |
+
torch = [
|
41 |
+
{ extra = "torch", index = "pypi" },
|
42 |
+
{ extra = "torch-cpu", index = "torch-cpu" },
|
43 |
+
{ extra = "torch-cu126", index = "torch-cu126" },
|
44 |
+
]
|
45 |
+
|
46 |
+
[[tool.uv.index]]
|
47 |
+
name = "torch-cpu"
|
48 |
+
url = "https://download.pytorch.org/whl/cpu"
|
49 |
+
explicit = true
|
50 |
|
51 |
[[tool.uv.index]]
|
52 |
name = "torch-cu126"
|
53 |
url = "https://download.pytorch.org/whl/cu126"
|
54 |
+
explicit = true
|
55 |
+
|
56 |
+
[[tool.uv.index]]
|
57 |
+
name = "pypi"
|
58 |
+
url = "https://pypi.python.org/simple"
|
59 |
|
60 |
[tool.ruff]
|
61 |
line-length = 120
|
src/rubik/interface/app.py
CHANGED
@@ -6,7 +6,7 @@ from rubik.cube import Cube
|
|
6 |
from rubik.interface.plot import CubeVisualizer
|
7 |
|
8 |
|
9 |
-
def app(default_size: int = 3):
|
10 |
"""
|
11 |
Interface with the following features:
|
12 |
- create a cube of the specified size.
|
@@ -62,5 +62,5 @@ def app(default_size: int = 3):
|
|
62 |
scramble_btn.click(scramble_cube, inputs=num_moves).success(display_cube, None, plot)
|
63 |
rotate_btn.click(rotate_cube, inputs=moves).success(display_cube, None, plot)
|
64 |
|
65 |
-
demo.launch()
|
66 |
return
|
|
|
6 |
from rubik.interface.plot import CubeVisualizer
|
7 |
|
8 |
|
9 |
+
def app(default_size: int = 3, server_port: int = 7860):
|
10 |
"""
|
11 |
Interface with the following features:
|
12 |
- create a cube of the specified size.
|
|
|
62 |
scramble_btn.click(scramble_cube, inputs=num_moves).success(display_cube, None, plot)
|
63 |
rotate_btn.click(rotate_cube, inputs=moves).success(display_cube, None, plot)
|
64 |
|
65 |
+
demo.launch(server_name="0.0.0.0", server_port=server_port)
|
66 |
return
|
uv.lock
CHANGED
The diff for this file is too large to render.
See raw diff
|
|