Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"editor.formatOnSave": true,
"editor.formatOnType": true,
"isort.args": [
"--gitignore",
"--profile",
"black"
]
Expand Down
7 changes: 2 additions & 5 deletions .devcontainer/dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#compatibility with Tensorflow 2.6.0 as per https://www.tensorflow.org/install/source#gpu
ARG PYTHON_VERSION=3.10
ARG UBUNTU_VERSION=noble
ARG POETRY_VERSION=1.8.2
ARG PYTHON_VERSION=3.11
ARG POETRY_VERSION=2.4.1
ARG CUDA_VERSION=12.6.1-base-ubuntu24.04

FROM nvidia/cuda:$CUDA_VERSION
Expand All @@ -19,7 +17,6 @@ RUN apt-get update && \
apt-get update && \
apt-get install --no-install-recommends -y \
python$PYTHON_VERSION \
python$PYTHON_VERSION-distutils \
python$PYTHON_VERSION-dev \
git vim curl gdb ca-certificates gnupg2 tar make gcc libssl-dev zlib1g-dev libncurses5-dev \
libbz2-dev libreadline-dev libreadline6-dev libxml2-dev xz-utils libgdbm-dev libgdbm-compat-dev tk-dev dirmngr \
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13", "3.14"]
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v6
Expand All @@ -29,6 +29,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 2.4.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand All @@ -48,14 +49,14 @@ jobs:
node-version: "24"
- name: Lint with pyright
run: |
npm install -g pyright@1.1.400
npm install -g pyright@1.1.411
poetry run pyright
- name: Test with pytest
run: poetry run pytest --cov --cov-report=xml
env:
EFLOMAL_PATH: /home/runner/work/machine.py/machine.py/.venv/lib/python${{ matrix.python-version }}/site-packages/eflomal/bin
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v7
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -65,22 +66,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
- name: Set up Python 3.10
- uses: actions/checkout@v7
- name: Set up Python 3.11
id: setup-python
uses: actions/setup-python@v6
with:
python-version: "3.10"
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 2.4.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Build
run: poetry build
- name: Upload package
uses: actions/upload-artifact@v6
uses: actions/upload-artifact@v7
with:
name: wheel
path: dist/*.whl
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
with:
docker-images: false
- name: Checkout
uses: actions/checkout@v6
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@v6
with:
images: ghcr.io/sillsdev/machine.py
tags: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ out/

# omit IDE data
.idea/

# Ignore Poetry plugins
.poetry/
8 changes: 4 additions & 4 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# syntax=docker/dockerfile:1.7-labs
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.12
ARG UBUNTU_VERSION=noble
ARG POETRY_VERSION=1.6.1
ARG POETRY_VERSION=2.4.1

FROM python:$PYTHON_VERSION-slim-bookworm AS builder
ARG POETRY_VERSION
Expand All @@ -19,7 +18,8 @@ RUN python3 -m venv $POETRY_VENV \
ENV PATH="${PATH}:${POETRY_VENV}/bin"

WORKDIR /src
COPY poetry.lock pyproject.toml /src
COPY poetry.lock pyproject.toml /src/
RUN poetry self add poetry-plugin-export
RUN poetry export --with=gpu --without-hashes -f requirements.txt > requirements.txt


Expand Down
8 changes: 4 additions & 4 deletions dockerfile.cpu_only
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# syntax=docker/dockerfile:1.7-labs
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.12
ARG UBUNTU_VERSION=noble
ARG POETRY_VERSION=1.6.1
ARG POETRY_VERSION=2.4.1

FROM python:$PYTHON_VERSION-slim-bookworm AS builder
ARG POETRY_VERSION
Expand All @@ -19,7 +18,8 @@ RUN python3 -m venv $POETRY_VENV \
ENV PATH="${PATH}:${POETRY_VENV}/bin"

WORKDIR /src
COPY poetry.lock pyproject.toml /src
COPY poetry.lock pyproject.toml /src/
RUN poetry self add poetry-plugin-export
RUN poetry export --extras="thot jobs" --without-hashes -f requirements.txt > requirements.txt


Expand Down
6 changes: 3 additions & 3 deletions machine/corpora/n_parallel_text_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ def default_row_ref_comparer(x: Any, y: Any) -> int:
# Do not use the default comparer for ScriptureRef, since we want to ignore segments
if isinstance(x, ScriptureRef) and isinstance(y, ScriptureRef):
return x.compare_to(y, False)
if x is None and y is not None:
return 1
if x is not None and y is None:
if x is None:
return 0 if y is None else 1
if y is None:
return -1
if x == y:
return 0
Expand Down
12 changes: 8 additions & 4 deletions machine/corpora/parallel_text_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,11 @@ def to_hf_dataset(
if text_id_column is not None:
features_dict[text_id_column] = Value("string")
if ref_column is not None:
features_dict[ref_column] = Sequence(Value("string"))
features_dict[ref_column] = cast(FeatureType, Sequence(Value("string")))
if alignment_column is not None:
features_dict[alignment_column] = Sequence({source_lang: Value("int32"), target_lang: Value("int32")})
features_dict[alignment_column] = cast(
FeatureType, Sequence({source_lang: Value("int32"), target_lang: Value("int32")})
)
if content_type_column is not None:
features_dict[content_type_column] = ClassLabel(names=[e.name for e in TextRowContentType])
features = Features(features_dict)
Expand Down Expand Up @@ -468,9 +470,11 @@ def to_hf_iterable_dataset(
if text_id_column is not None:
features_dict[text_id_column] = Value("string")
if ref_column is not None:
features_dict[ref_column] = Sequence(Value("string"))
features_dict[ref_column] = cast(FeatureType, Sequence(Value("string")))
if alignment_column is not None:
features_dict[alignment_column] = Sequence({source_lang: Value("int32"), target_lang: Value("int32")})
features_dict[alignment_column] = cast(
FeatureType, Sequence({source_lang: Value("int32"), target_lang: Value("int32")})
)
features = Features(features_dict)

if info is not None and info.features is not None and info.features != features:
Expand Down
2 changes: 1 addition & 1 deletion machine/translation/huggingface/hugging_face_nmt_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
):
self._pipeline_kwargs["prefix"] = f"translate {src_lang} to {tgt_lang}: "
else:
additional_special_tokens = self._tokenizer.additional_special_tokens
additional_special_tokens = cast(list[str], self._tokenizer.additional_special_tokens or [])
if isinstance(self._tokenizer, M2M100Tokenizer):
src_lang_token = self._tokenizer.lang_code_to_token.get(src_lang) if src_lang is not None else None
tgt_lang_token = self._tokenizer.lang_code_to_token.get(tgt_lang) if tgt_lang is not None else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ def add_tokens(tokenizer: Any, missing_tokens: List[str]) -> Any:
# For multilingual translation models like mBART-50 and M2M100 we need to force the target language token
# as the first generated token. We ask the user to explicitly provide this as --forced_bos_token argument.
forced_bos_token_id = tokenizer.convert_tokens_to_ids(self._tgt_lang)
model.config.forced_bos_token_id = forced_bos_token_id
if model.generation_config is not None:
model.generation_config.forced_bos_token_id = forced_bos_token_id
else:
model.config.forced_bos_token_id = forced_bos_token_id

prefix = ""
if model.name_or_path.startswith("t5-") or model.name_or_path.startswith("google/mt5-"):
Expand Down
Loading
Loading