Skip to content

Commit 85814b4

Browse files
committed
Fixed torch development versions
1 parent 9736910 commit 85814b4

12 files changed

Lines changed: 1866 additions & 676 deletions

File tree

.devcontainer/cpu/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ USER $USERNAME
1818
WORKDIR /home/$USERNAME
1919
RUN ["/bin/bash", "-c", "set -o pipefail && wget -qO - https://astral.sh/uv/install.sh | sh"]
2020
ENV PATH="/home/$USERNAME/.local/bin/:$PATH"
21+
22+
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
23+
--mount=type=bind,source=.python-version,target=.python-version \
24+
uv python install
25+
2126
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
2227
--mount=type=bind,source=.python-version,target=.python-version \
2328
uv sync --no-install-project --no-install-workspace

.devcontainer/cpu/devcontainer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
"vscode": {
1616
// Add the IDs of extensions you want installed when the container is created.
1717
"extensions": ["streetsidesoftware.code-spell-checker",
18-
"ms-toolsai.jupyter",
19-
"ms-toolsai.jupyter-renderers",
2018
"ms-python.python",
21-
"ms-python.vscode-pylance",
19+
"astral-sh.ty",
20+
"ms-python.vscode-python-envs",
2221
"ms-vscode.makefile-tools",
2322
"redhat.vscode-yaml",
2423
"tamasfe.even-better-toml",
25-
"github.vscode-github-actions"]
24+
"github.vscode-github-actions",
25+
"mechatroner.rainbow-csv",
26+
"ms-azuretools.vscode-docker",
27+
"ms-azuretools.vscode-containers"]
2628
}
2729
},
28-
"postStartCommand": "uv sync"
30+
"postStartCommand": "uv sync --all-extras"
2931
}

.devcontainer/gpu/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ USER $USERNAME
1616
WORKDIR /home/$USERNAME
1717
RUN ["/bin/bash", "-c", "set -o pipefail && wget -qO- https://astral.sh/uv/install.sh | sh"]
1818
ENV PATH="/home/$USERNAME/.local/bin/:$PATH"
19-
RUN ls -alh
20-
RUN pwd
19+
20+
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
21+
--mount=type=bind,source=.python-version,target=.python-version \
22+
uv python install
23+
2124
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
2225
--mount=type=bind,source=.python-version,target=.python-version \
23-
uv sync --no-install-project --no-install-workspace
26+
uv sync --no-install-project --no-install-workspace --no-group cpu --group cu128

.devcontainer/gpu/devcontainer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
"vscode": {
1616
// Add the IDs of extensions you want installed when the container is created.
1717
"extensions": ["streetsidesoftware.code-spell-checker",
18-
"ms-toolsai.jupyter",
19-
"ms-toolsai.jupyter-renderers",
2018
"ms-python.python",
21-
"ms-python.vscode-pylance",
19+
"astral-sh.ty",
20+
"ms-python.vscode-python-envs",
2221
"ms-vscode.makefile-tools",
2322
"redhat.vscode-yaml",
2423
"tamasfe.even-better-toml",
25-
"github.vscode-github-actions"]
24+
"github.vscode-github-actions",
25+
"mechatroner.rainbow-csv",
26+
"ms-azuretools.vscode-docker",
27+
"ms-azuretools.vscode-containers"]
2628
}
2729
},
28-
"postStartCommand": "uv sync"
30+
"postStartCommand": "uv sync --no-group cpu --group cu128"
2931
}

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
*
22
! pyproject.toml
3-
! uv.lock
43
! .python-version

.github/workflows/ci.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,26 @@ jobs:
2020
os: [ubuntu-latest, windows-latest, macos-latest]
2121

2222
steps:
23-
- uses: actions/checkout@v5
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.02
2424

2525
- name: Set up Python 3.13
26-
uses: actions/setup-python@v6
26+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2
2727
id: python-setup
2828
with:
2929
python-version: 3.13
3030

3131
- name: Install uv
32-
uses: astral-sh/setup-uv@v7
32+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
3333
id: setup-uv
3434
with:
3535
# Install a specific version of uv.
36-
version: "0.9.10"
36+
version: "0.11.7"
3737
enable-cache: true
3838
restore-cache: true
3939
save-cache: true
4040
prune-cache: true
4141
cache-dependency-glob: "uv.lock"
42+
python-version: 3.13
4243

4344
- name: Install the project
4445
run: uv sync --locked
@@ -48,7 +49,7 @@ jobs:
4849
run: echo "uv cache was restored"
4950

5051
- name: Check HF model cache
51-
uses: actions/cache/restore@v4
52+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
5253
id: cache
5354
with:
5455
path: ~/hf_test_model_cache
@@ -59,7 +60,7 @@ jobs:
5960
run: uv run tests/model_download.py $HOME/hf_test_model_cache
6061

6162
- name: Saving HuggingFace test model
62-
uses: actions/cache/save@v4
63+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
6364
if: steps.cache.outputs.cache-hit != 'true'
6465
with:
6566
path: ~/hf_test_model_cache
@@ -80,25 +81,26 @@ jobs:
8081
HF_HOME: /path/to/cache_root
8182

8283
steps:
83-
- uses: actions/checkout@v5
84+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.02
8485

8586
- name: Set up Python ${{ matrix.python-version }}
86-
uses: actions/setup-python@v6
87+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2
8788
id: python-setup
8889
with:
8990
python-version: ${{ matrix.python-version }}
9091

9192
- name: Install uv
92-
uses: astral-sh/setup-uv@v7
93+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
9394
id: setup-uv
9495
with:
9596
# Install a specific version of uv.
96-
version: "0.9.10"
97+
version: "0.11.7"
9798
enable-cache: true
9899
restore-cache: true
99100
save-cache: true
100101
prune-cache: true
101102
cache-dependency-glob: "uv.lock"
103+
python-version: ${{ matrix.python-version }}
102104

103105
- name: Install the project
104106
run: uv sync --locked
@@ -115,7 +117,7 @@ jobs:
115117
uv run flake8 --config .flake8 src tests
116118
117119
- name: Cache mypy
118-
uses: actions/cache@v4
120+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
119121
with:
120122
path: ./.mypy_cache
121123
key: ${{ runner.os }}-${{ steps.python-setup.outputs.python-version }}-${{ hashFiles('uv.lock') }}
@@ -138,14 +140,14 @@ jobs:
138140
echo "HF_HOME=$HOME/.cache/huggingface" >> "$GITHUB_ENV"
139141
140142
- name: Get HF model cache
141-
uses: actions/cache/restore@v4
143+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
142144
with:
143145
path: ~/hf_test_model_cache
144146
key: ettin-17m-model-${{ runner.os }}
145147
lookup-only: false
146148

147149
- name: Move cached files
148-
run: mv $HOME/hf_test_model_cache/* $HOME/.cache/huggingface/hub/.
150+
run: mv $HOME/hf_test_model_cache/* $HF_HOME/hub/.
149151

150152

151153
- name: Code coverage testing

.github/workflows/publish.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v5
18+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.02
1919

2020
- name: Set up Python 3.13
21-
uses: actions/setup-python@v6
21+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2
2222
id: python-setup
2323
with:
2424
python-version: 3.13
2525

2626
- name: Install uv
27-
uses: astral-sh/setup-uv@v7
27+
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
2828
id: setup-uv
2929
with:
3030
# Install a specific version of uv.
31-
version: "0.9.10"
31+
version: "0.11.7"
3232
enable-cache: false
3333
restore-cache: false
3434
save-cache: false
35+
python-version: 3.13
3536

3637
- name: Build release distributions
3738
run: |

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
- Added the arXiv paper to the PyMUSAS BEM model readme, `model_readmes/pymusas_bem.md`, of which this did require the Bib text to be Python string variable in the convert and upload script `scripts/convert_and_upload_bem_model.py`.
11+
- Changed the [./pyproject.toml](./pyproject.toml) so that local developers can easily install different versions of torch, i.e. cpu or different cuda versions.
12+
- Updated the [./.github/workflows](./.github/workflows) to use specific GitHub action versions, this should make the workflow more secure.
13+
- Updated the [./.devcontainer](./.devcontainer) files so that they use the correct version of torch.
1114

1215
## [v0.1.2](https://github.com/UCREL/WSD-Torch-Models/releases/tag/v0.1.2) - 2025-12-10
1316

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ Requires Python `3.10` or greater, it is best that you install the version of Py
1010
pip install wsd-torch-models
1111
```
1212

13+
To install with a different version of `torch`, e.g. `cuda`:
14+
15+
``` bash
16+
pip install torch --index-url https://download.pytorch.org/whl/cu128
17+
pip install wsd-torch-models
18+
```
19+
1320
## Models with examples
1421

1522
Here we list the various WSD models we have implemented and how to use them.
@@ -209,6 +216,25 @@ When developing on the project you will want to install the Python package local
209216
uv sync
210217
```
211218

219+
This version of `uv sync` will install the CPU version of `torch` to install a `cuda` version, i.e. `cuda 12.8` run the following:
220+
221+
``` bash
222+
uv sync --no-group cpu --group cu128
223+
```
224+
225+
Currently we support `cu126`, `cu128`, and `cu130`, see the [./pyproject.toml](./pyproject.toml) for more information.
226+
227+
228+
**NOTE** if using `--no-group cpu --group XXX` then each time you use `uv run` you need to use `uv run --no-group cpu --group XXX`
229+
230+
We have made it slightly simpler with `make` at least for `cu128` (which can be used as template for the other versions) with:
231+
232+
``` bash
233+
make run-cu128 CMD="python ANY OTHER ARGUMENTS" # Runs Python or any other command that you would after `uv run`
234+
make tests-cu128 # Runs the tests
235+
make lint-cu128 # Runs the linting
236+
```
237+
212238
### Running linters and tests
213239

214240
This code base uses isort, flake8 and mypy to ensure that the format of the code is consistent and contain type hints. ISort and mypy settings can be found within [./pyproject.toml](./pyproject.toml) and the flake8 settings can be found in [./.flake8](./.flake8). To run these linters:

makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,23 @@ build-python-package:
2525
release-notes: build-python-package
2626
@uv run --no-project --script \
2727
--with dist/wsd_torch_models-$$("${VERSION_CMD}")-py3-none-any.whl \
28-
./scripts/release_notes.py
28+
./scripts/release_notes.py
29+
30+
.PHONY: run-cu128
31+
run-cu128:
32+
@uv run --no-group cpu --group cu128 $(CMD)
33+
34+
.PHONY: tests-cu128
35+
tests-cu128:
36+
@uv run --no-group cpu --group cu128 coverage run
37+
@uv run --no-group cpu --group cu128 coverage report
38+
39+
.PHONY: lint-cu128
40+
lint-cu128:
41+
@echo "ISort:"
42+
@uv run --no-group cpu --group cu128 isort src tests scripts
43+
@echo "Flake 8:"
44+
@uv run --no-group cpu --group cu128 flake8 --config ./.flake8 src tests
45+
@echo "MyPy:"
46+
@uv run --no-group cpu --group cu128 mypy
47+
@echo "Linting finished"

0 commit comments

Comments
 (0)