Theo Korir commited on
Commit
e71eede
·
unverified ·
2 Parent(s): 3f3eddcfb36c84

Merge pull request #6 from spacey-cadet/aws-serverless

Browse files
.github/workflows/deploy-aws-serverless.yml CHANGED
@@ -40,7 +40,7 @@ jobs:
40
  run: |
41
  docker buildx build --platform linux/amd64 \
42
  --provenance=false --sbom=false \
43
- --build-arg HF_MODEL_REPO=${{ vars.HF_MODEL_REPO }} \
44
  --build-arg HF_MODEL_REVISION=${{ vars.HF_CHAMPION_REVISION }} \
45
  --build-arg HF_TOKEN=${{ secrets.HF_TOKEN }} \
46
  -f infra/aws-serverless/Dockerfile.lambda \
 
40
  run: |
41
  docker buildx build --platform linux/amd64 \
42
  --provenance=false --sbom=false \
43
+ --build-arg MODEL_ID=${{ vars.HF_MODEL}} \
44
  --build-arg HF_MODEL_REVISION=${{ vars.HF_CHAMPION_REVISION }} \
45
  --build-arg HF_TOKEN=${{ secrets.HF_TOKEN }} \
46
  -f infra/aws-serverless/Dockerfile.lambda \
infra/aws-serverless/Dockerfile.lambda CHANGED
@@ -1,4 +1,6 @@
 
1
  # infra/aws-serverless/Dockerfile.lambda
 
2
  #
3
  # Bakes the model in at BUILD time by calling the real
4
  # app.model.loader.load_model()/verify_model() — not a reimplemented
@@ -21,7 +23,7 @@
21
  FROM public.ecr.aws/lambda/python:3.11
22
 
23
  # WavLM (torch) needs OpenMP, same fix as lightgbm needed in Project 1.
24
- RUN yum install -y libgomp pkgconfig ffmpeg-devel && yum clean all
25
 
26
  COPY requirements.txt .
27
  # requirements.txt must already include speechbrain (it does, if this
@@ -34,6 +36,11 @@ COPY app/ ${LAMBDA_TASK_ROOT}/app/
34
 
35
  ARG MODEL_ID
36
  ARG HF_TOKEN=""
 
 
 
 
 
37
  # Absolute path — config.py's default "./model_cache" is relative,
38
  # which would resolve against Lambda's read-only filesystem at
39
  # runtime. Bake into and read from this exact absolute path both
@@ -46,22 +53,27 @@ ENV CACHE_DIR=${LAMBDA_TASK_ROOT}/model_cache
46
  # at BUILD time, so a broken checkpoint fails the build, not a live
47
  # Lambda. revision is always "main" — config.py's Settings has no
48
  # separate revision field, so the champion is whatever's on main.
49
- RUN python -c "\
50
- import os, sys; \
51
- sys.path.insert(0, os.environ['LAMBDA_TASK_ROOT']); \
52
- from app.model.loader import load_model, verify_model; \
53
- m = load_model( \
54
- model_id=os.environ['MODEL_ID'], \
55
- hf_token=os.environ.get('HF_TOKEN') or None, \
56
- cache_dir=os.environ['CACHE_DIR'], \
57
- revision='main', \
58
- ); \
59
- verify_model(m); \
60
- print('Baked and verified:', m.revision_tag)"
 
 
 
 
 
 
61
 
62
  ENV STORAGE_BACKEND=aws
63
  ENV HF_HUB_OFFLINE=1
64
- ENV MODEL_ID=${MODEL_ID}
65
 
66
  # KNOWN RISK, not yet verified: speechbrain's WavLM() wrapper downloads
67
  # the frozen microsoft/wavlm-base-plus backbone via its own HF
 
1
+ # syntax=docker/dockerfile:1.4
2
  # infra/aws-serverless/Dockerfile.lambda
3
+
4
  #
5
  # Bakes the model in at BUILD time by calling the real
6
  # app.model.loader.load_model()/verify_model() — not a reimplemented
 
23
  FROM public.ecr.aws/lambda/python:3.11
24
 
25
  # WavLM (torch) needs OpenMP, same fix as lightgbm needed in Project 1.
26
+ RUN yum install -y libgomp libsndfile && yum clean all
27
 
28
  COPY requirements.txt .
29
  # requirements.txt must already include speechbrain (it does, if this
 
36
 
37
  ARG MODEL_ID
38
  ARG HF_TOKEN=""
39
+ # ARG only makes these available for Dockerfile ${...} substitution —
40
+ # it does NOT populate the process environment that os.environ reads
41
+ # from inside a RUN step. ENV must come before the RUN below that
42
+ # actually consumes MODEL_ID via os.environ['MODEL_ID'].
43
+ ENV MODEL_ID=${MODEL_ID}
44
  # Absolute path — config.py's default "./model_cache" is relative,
45
  # which would resolve against Lambda's read-only filesystem at
46
  # runtime. Bake into and read from this exact absolute path both
 
53
  # at BUILD time, so a broken checkpoint fails the build, not a live
54
  # Lambda. revision is always "main" — config.py's Settings has no
55
  # separate revision field, so the champion is whatever's on main.
56
+ RUN <<EOF
57
+ #!/usr/bin/env python3
58
+ import os, sys, traceback
59
+ sys.path.insert(0, os.environ['LAMBDA_TASK_ROOT'])
60
+ try:
61
+ from app.model.loader import load_model, verify_model
62
+ m = load_model(
63
+ model_id=os.environ['MODEL_ID'],
64
+ hf_token=os.environ.get('HF_TOKEN') or None,
65
+ cache_dir=os.environ['CACHE_DIR'],
66
+ revision='main',
67
+ )
68
+ verify_model(m)
69
+ print('Baked and verified:', m.revision_tag)
70
+ except Exception:
71
+ traceback.print_exc()
72
+ sys.exit(1)
73
+ EOF
74
 
75
  ENV STORAGE_BACKEND=aws
76
  ENV HF_HUB_OFFLINE=1
 
77
 
78
  # KNOWN RISK, not yet verified: speechbrain's WavLM() wrapper downloads
79
  # the frozen microsoft/wavlm-base-plus backbone via its own HF
requirements.txt CHANGED
@@ -8,9 +8,9 @@ pydantic-settings
8
  # Model / inference
9
  torch
10
  torchaudio
11
- transformers
 
12
  speechbrain
13
- huggingface_hub
14
  av
15
  numpy>=1.26,<2.2
16
  soundfile
 
8
  # Model / inference
9
  torch
10
  torchaudio
11
+ transformers>=4.30,<5
12
+ huggingface_hub>=0.20,<1
13
  speechbrain
 
14
  av
15
  numpy>=1.26,<2.2
16
  soundfile