Skip to content

Commit 8b330df

Browse files
kimdwkimdwjongwook
andauthored
Add .pre-commit-config.yaml (#1528)
* Add .pre-commit-config.yaml Co-authored-by: arthur <[email protected]> * flake8 E741 --------- Co-authored-by: Jong Wook Kim <[email protected]>
1 parent 21010ef commit 8b330df

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

.github/workflows/test.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,38 @@ on:
66
pull_request:
77
branches:
88
- main
9+
910
jobs:
11+
pre-commit:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Fetch base branch
16+
run: git fetch origin ${{ github.base_ref }}
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.8"
20+
architecture: x64
21+
- name: Get pip cache dir
22+
id: pip-cache
23+
run: |
24+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
25+
- name: pip/pre-commit cache
26+
uses: actions/cache@v3
27+
with:
28+
path: |
29+
${{ steps.pip-cache.outputs.dir }}
30+
~/.cache/pre-commit
31+
key: ${{ runner.os }}-pip-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
32+
restore-keys: |
33+
${{ runner.os }}-pip-pre-commit
34+
- name: pre-commit
35+
run: |
36+
pip install -U pre-commit
37+
pre-commit install --install-hooks
38+
pre-commit run --from-ref=origin/${{ github.base_ref }} --to-ref=HEAD
1039
whisper-test:
40+
needs: pre-commit
1141
runs-on: ubuntu-latest
1242
strategy:
1343
matrix:
@@ -23,7 +53,4 @@ jobs:
2353
- uses: actions/checkout@v3
2454
- run: echo "$CONDA/envs/test/bin" >> $GITHUB_PATH
2555
- run: pip install .["dev"]
26-
- run: black --check --diff -t py38 --include '(\.pyi?)$' .
27-
- run: isort --check --diff .
28-
- run: flake8 --ignore E203,W503,W504,E501,E731,E741 .
2956
- run: pytest --durations=0 -vv -k 'not test_transcribe or test_transcribe[tiny] or test_transcribe[tiny.en]' -m 'not requires_cuda'

.pre-commit-config.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: check-json
6+
- id: end-of-file-fixer
7+
types: [file, python]
8+
- id: trailing-whitespace
9+
types: [file, python]
10+
- id: mixed-line-ending
11+
- id: check-added-large-files
12+
args: [--maxkb=4096]
13+
- repo: https://github.com/psf/black
14+
rev: 23.7.0
15+
hooks:
16+
- id: black
17+
- repo: https://github.com/pycqa/isort
18+
rev: 5.12.0
19+
hooks:
20+
- id: isort
21+
name: isort (python)
22+
args: ["--profile", "black", "-l", "88", "--trailing-comma", "--multi-line", "3"]
23+
- repo: https://github.com/pycqa/flake8.git
24+
rev: 6.0.0
25+
hooks:
26+
- id: flake8
27+
types: [python]
28+
args: ["--max-line-length", "88", "--ignore", "E203,E501,W503,W504"]

whisper/timing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def find_alignment(
202202
hook.remove()
203203

204204
# heads * tokens * frames
205-
weights = torch.stack([QKs[l][h] for l, h in model.alignment_heads.indices().T])
205+
weights = torch.stack([QKs[_l][_h] for _l, _h in model.alignment_heads.indices().T])
206206
weights = weights[:, :, : num_frames // 2]
207207
weights = (weights * qk_scale).softmax(dim=-1)
208208
std, mean = torch.std_mean(weights, dim=-2, keepdim=True, unbiased=False)

whisper/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def all_language_tokens(self) -> Tuple[int]:
226226

227227
@cached_property
228228
def all_language_codes(self) -> Tuple[str]:
229-
return tuple(self.decode([l]).strip("<|>") for l in self.all_language_tokens)
229+
return tuple(self.decode([_l]).strip("<|>") for _l in self.all_language_tokens)
230230

231231
@cached_property
232232
def sot_sequence_including_notimestamps(self) -> Tuple[int]:

0 commit comments

Comments
 (0)