Skip to content

Commit 7d19c3f

Browse files
committed
chore(ci): fix test path for scripts
1 parent 8fb2764 commit 7d19c3f

File tree

7 files changed

+174
-227
lines changed

7 files changed

+174
-227
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ on:
66
artifact-name:
77
description: "Name of the artifact containing the built package"
88
value: ${{ jobs.build.outputs.artifact-name }}
9-
pull_request:
10-
branches: [ main ]
11-
push:
12-
branches: [ main ]
139

1410
jobs:
1511
build:
@@ -35,20 +31,26 @@ jobs:
3531
poetry config virtualenvs.create true --local
3632
poetry config virtualenvs.in-project true --local
3733
34+
# Add caching for Poetry dependencies
35+
- name: Cache Poetry dependencies
36+
uses: actions/cache@v3
37+
with:
38+
path: .venv
39+
key: ${{ runner.os }}-poetry-3.9-${{ hashFiles('**/poetry.lock') }}
40+
restore-keys: |
41+
${{ runner.os }}-poetry-3.9-
42+
3843
- name: Install dependencies
3944
run: poetry install
4045

4146
- name: Build package
4247
run: poetry build
4348

44-
- name: Upload artifact
45-
uses: actions/upload-artifact@v4
49+
- name: Upload build artifacts
50+
uses: actions/upload-artifact@v3
4651
with:
4752
name: dist
4853
path: dist/
49-
retention-days: 1
5054

5155
- name: Check code quality
52-
run: |
53-
poetry run black --check babeltron/
54-
poetry run isort --check-only babeltron/
56+
run: make lint

.github/workflows/publish.yml

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,31 @@
11
name: Publish Package
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
4+
release:
5+
types: [created]
76

87
jobs:
9-
test:
10-
uses: ./.github/workflows/test.yml
11-
128
build:
13-
needs: test
149
uses: ./.github/workflows/build.yml
1510

16-
publish:
11+
test:
1712
needs: build
18-
runs-on: ubuntu-latest
13+
uses: ./.github/workflows/test.yml
14+
with:
15+
python-version: '3.9'
16+
upload-coverage: true
1917

18+
publish:
19+
needs: [build, test]
20+
runs-on: ubuntu-latest
2021
steps:
21-
- uses: actions/checkout@v4
22-
23-
- name: Set up Python
24-
uses: actions/setup-python@v5
25-
with:
26-
python-version: '3.9'
27-
28-
- name: Install Poetry
29-
uses: abatilo/actions-poetry@v4
30-
with:
31-
poetry-version: latest
32-
33-
- name: Setup virtualenv
34-
run: |
35-
poetry config virtualenvs.create true --local
36-
poetry config virtualenvs.in-project true --local
37-
38-
- name: Configure Poetry
39-
run: |
40-
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
41-
42-
# - name: Download artifact
43-
# uses: actions/download-artifact@v4
44-
# with:
45-
# name: ${{ needs.build.outputs.artifact-name }}
46-
# path: dist
47-
48-
# - name: Publish to PyPI
49-
# run: poetry publish
50-
# env:
51-
# POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
22+
- name: Download build artifacts
23+
uses: actions/download-artifact@v3
24+
with:
25+
name: dist
26+
path: dist/
27+
28+
- name: Publish to PyPI
29+
uses: pypa/gh-action-pypi-publish@release/v1
30+
with:
31+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@ name: Tests
22

33
on:
44
workflow_call:
5-
pull_request:
6-
branches: [ main ]
7-
push:
8-
branches: [ main ]
5+
inputs:
6+
python-version:
7+
description: 'Python version to use'
8+
required: false
9+
default: '3.9'
10+
type: string
11+
upload-coverage:
12+
description: 'Whether to upload coverage reports'
13+
required: false
14+
default: true
15+
type: boolean
916

1017
jobs:
1118
test:
1219
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
16-
1720
steps:
1821
- uses: actions/checkout@v4
1922

20-
- name: Set up Python ${{ matrix.python-version }}
23+
- name: Set up Python ${{ inputs.python-version }}
2124
uses: actions/setup-python@v5
2225
with:
23-
python-version: ${{ matrix.python-version }}
26+
python-version: ${{ inputs.python-version }}
2427

2528
- name: Install Poetry
2629
uses: abatilo/actions-poetry@v4
@@ -32,17 +35,22 @@ jobs:
3235
poetry config virtualenvs.create true --local
3336
poetry config virtualenvs.in-project true --local
3437
38+
- name: Cache Poetry dependencies
39+
uses: actions/cache@v3
40+
with:
41+
path: .venv
42+
key: ${{ runner.os }}-poetry-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-poetry-${{ inputs.python-version }}-
45+
3546
- name: Install dependencies
3647
run: poetry install
3748

3849
- name: Run tests
3950
run: make test
4051

41-
- name: Check code quality
42-
run: |
43-
make lint
44-
4552
- name: Upload coverage reports to Codecov
53+
if: inputs.upload-coverage
4654
uses: codecov/codecov-action@v3
4755
env:
4856
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

babeltron/scripts/__init__.py

Whitespace-only changes.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to download M2M-100 models for Babeltron.
4+
"""
5+
import argparse
6+
import os
7+
from pathlib import Path
8+
from typing import List, Optional, Union
9+
10+
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
11+
12+
VALID_MODEL_SIZES: List[str] = os.environ.get(
13+
"BABELTRON_MODEL_SIZES", "418M,1.2B,12B"
14+
).split(",")
15+
DEFAULT_MODEL_SIZE: str = os.environ.get("BABELTRON_DEFAULT_MODEL_SIZE", "418M")
16+
DEFAULT_OUTPUT_DIR: Path = Path.home() / "models"
17+
18+
19+
def parse_args():
20+
parser = argparse.ArgumentParser(description="Download M2M100 translation models")
21+
parser.add_argument(
22+
"--size",
23+
choices=VALID_MODEL_SIZES,
24+
default=DEFAULT_MODEL_SIZE,
25+
help="Model size to download (418M, 1.2B, or 12B)",
26+
)
27+
parser.add_argument(
28+
"--output-dir", default=DEFAULT_OUTPUT_DIR, help="Directory to save the model"
29+
)
30+
return parser.parse_args()
31+
32+
33+
def download_model(
34+
model_size: str = DEFAULT_MODEL_SIZE,
35+
output_dir: Optional[Union[str, Path]] = None,
36+
show_progress: bool = True,
37+
) -> str:
38+
"""
39+
Download M2M-100 model and tokenizer.
40+
41+
Args:
42+
model_size (str): Size of the model to download (418M, 1.2B, or 12B)
43+
output_dir (str or Path, optional): Directory to save the model to
44+
show_progress (bool): Whether to show a progress bar
45+
46+
Returns:
47+
str: Path to the downloaded model directory
48+
"""
49+
if model_size not in VALID_MODEL_SIZES:
50+
raise ValueError(f"Model size must be one of {VALID_MODEL_SIZES}")
51+
52+
model_name = f"facebook/m2m100_{model_size}"
53+
54+
if output_dir is None:
55+
output_dir = DEFAULT_OUTPUT_DIR
56+
else:
57+
output_dir = Path(output_dir)
58+
59+
output_dir.mkdir(parents=True, exist_ok=True)
60+
61+
print(f"Downloading {model_name} model and tokenizer to {output_dir}...")
62+
63+
print("Downloading tokenizer...")
64+
tokenizer = M2M100Tokenizer.from_pretrained(model_name)
65+
tokenizer.save_pretrained(output_dir)
66+
67+
print("Downloading model (this may take a while)...")
68+
model = M2M100ForConditionalGeneration.from_pretrained(model_name)
69+
model.save_pretrained(output_dir)
70+
71+
print(f"Model and tokenizer successfully saved to {output_dir}")
72+
73+
return str(output_dir)
74+
75+
76+
def main():
77+
args = parse_args()
78+
79+
try:
80+
model_map = {"418M": "418M", "1.2B": "1.2B", "12B": "12B"}
81+
82+
model_size = model_map[args.size]
83+
output_dir = args.output_dir
84+
85+
print(f"Downloading {args.size} model...")
86+
print(
87+
"This may take a while depending on your internet connection and the model size."
88+
)
89+
90+
download_model(model_size=model_size, output_dir=output_dir)
91+
92+
print(f"Model successfully downloaded and saved to {output_dir}")
93+
94+
except Exception as e:
95+
print(f"Error downloading model: {e}")
96+
return 1
97+
98+
return 0
99+
100+
101+
if __name__ == "__main__":
102+
main()

0 commit comments

Comments
 (0)