Skip to content

Commit 1ccb0a4

Browse files
chore: finalize v1 release readiness fixes
1 parent 21e2e12 commit 1ccb0a4

54 files changed

Lines changed: 5646 additions & 3486 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ cython_debug/
111111
## User folders
112112
models/
113113
models_local/
114-
model_defs/
115114
outputs/
116115
tests/data/output/
117116
data/3dmm/
118-
scripts/upload_models_hf.py
117+
scripts/upload_models_hf.py

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
## 1.0.0
44

5-
Released on April 18, 2026.
5+
Released on May 1, 2026.
66

77
### Breaking Changes
88
* Minimum Python version raised from 3.8 to 3.10
9+
* Supported Python range is now explicitly capped at `<3.14`, matching the tested v1 CI matrix
910
* Minimum PyTorch version raised from 1.9 to 2.3
1011
* All models migrated from TorchScript (.pt) to torch.export (.pt2) format
12+
* Default model loading now relies on Hugging Face `.pt2` artifacts; Google Drive/TorchScript artifacts are retained only as legacy fallbacks where available
1113
* `path_image` and `tensor` parameters in `FaceAnalyzer.run()` are deprecated in favor of `image_source`
1214

1315
### Added
@@ -21,13 +23,15 @@ Released on April 18, 2026.
2123
* Torch-versioned exported model cohorts and runtime fallback routing for `.pt2` artifacts (for example `model-torch2.3.pt2`, `model-torch2.6.pt2`, `model-torch2.11.pt2`)
2224
* Cohort export/validation/upload script: `scripts/export_model_cohorts_hf.py`
2325
* Device-aware cohort validation in export script via `--validate-devices` (for example `cpu,cuda`)
26+
* Export-only `model_defs/` architecture definitions for reproducible `.pt2` cohort generation without making them runtime model dependencies
2427
* Dependency alignment check script: `scripts/check_dependency_sync.py`
2528
* `uv.lock` for reproducible PyPI-based dependency resolution
2629
* `[tool.uv]` configuration in `pyproject.toml`
2730

2831
### Changed
2932
* Migrated from `setup.py` + `version` file to `pyproject.toml` (PEP 621)
3033
* All model files migrated from TorchScript (.pt) to torch.export (.pt2) portable format with dynamic batch support
34+
* Model artifact strategy changed to prioritize portability and install-time simplicity over TorchScript-specific runtime behavior: `.pt2` artifacts do not require bundled model source code, while versioned cohorts handle PyTorch exported-program schema differences across supported torch runtimes (`2.3`, `2.6`, `2.11`)
3135
* AU predictor model rewritten with timm Swin Transformer backbone for torch.export compatibility
3236
* Docker dev/test images migrated from conda/conda-lock to [uv](https://github.com/astral-sh/uv) for faster builds
3337
* Docker production images now use uv as a pip drop-in
@@ -45,6 +49,8 @@ Released on April 18, 2026.
4549
* Numpy array reader now handles (H, W) and (H, W, 1) grayscale arrays
4650
* AU `.pt2` CUDA device mismatch by re-exporting validated AU cohorts (`2.3`, `2.6`, `2.11`) and publishing refreshed Hugging Face artifacts with metadata
4751
* Exported-model schema mismatch fallback now also handles additional cross-version `.pt2` archive load errors (for example missing `version` entry)
52+
* Export cohort validation now fails on numerical drift beyond configured max/mean absolute-difference tolerances instead of only recording comparison metrics
53+
* Test configs now resolve `/opt/facetorch` paths to the checked-out repository during local pytest runs, while preserving Docker CI behavior
4854

4955

5056
## 0.6.2

MANIFEST.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ include pyproject.toml
33
include environment.yml
44
recursive-include conf *
55
recursive-include docs *
6+
recursive-include model_defs *.py *.md
7+
include scripts/check_dependency_sync.py
8+
include scripts/example.py
9+
include scripts/example_tensor.py
10+
include scripts/export_model_cohorts_hf.py
11+
include scripts/repeated_inference.py
612
include data/input*/*.jpg
713
include data*/*.png
814
include tests*/*.py

README.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Facetorch provides an efficient, scalable, and user-friendly solution for facial
3333

3434
### Requirements
3535

36-
* Python >= 3.10
36+
* Python >= 3.10 and < 3.14
3737
* PyTorch >= 2.3 (facetorch routes exported model artifacts by torch minor version)
3838

3939
Please use this library responsibly and with caution. Adhere to the [European Commission's Ethics Guidelines for Trustworthy AI](https://ec.europa.eu/futurium/en/ai-alliance-consultation.1.html) to ensure ethical and fair usage. Keep in mind that the models may have limitations and potential biases, so it is crucial to evaluate their outputs critically and consider their impact.
@@ -229,22 +229,47 @@ Models are available on the [Hugging Face Hub](https://huggingface.co/tomas-gaja
229229
For exported `.pt2` models, facetorch can fall back across versioned artifacts when present (e.g. `model-torch2.3.pt2`, `model-torch2.6.pt2`, `model-torch2.11.pt2`).
230230
By default, the downloader tries `model.pt2` first, then versioned cohort artifacts, and finally `model.pt` as a legacy fallback where available.
231231

232+
#### Why exported models?
233+
234+
Facetorch v1 moved default model artifacts from TorchScript (`.pt`) to `torch.export` (`.pt2`) so inference no longer depends on bundled model source code, custom class definitions, or TorchScript-specific runtime behavior. This makes the hosted models easier to validate, redistribute, and load across normal Python package installations. TorchScript artifacts are still useful as legacy fallbacks, but v1 workflows should prefer Hugging Face `.pt2` artifacts.
235+
236+
`torch.export` serialization is tied to PyTorch's exported-program schema, so one `.pt2` file is not guaranteed to load across every future or older PyTorch minor version. To avoid pinning users to one narrow torch version, facetorch publishes and validates cohort artifacts for representative supported runtimes: `torch 2.3`, `torch 2.6`, and `torch 2.11`. Runtime support starts at `PyTorch >= 2.3`; when versioned cohorts are available, the downloader selects from those artifacts and falls back to the next candidate if the current runtime cannot load the first choice.
237+
232238

233239
### Execution time
234240

235-
Reference GPU benchmark (warm second pass, batch_size=8, utilizers disabled):
236-
- `test.jpg` (4 faces): pass1 `672 ms`, pass2 `209 ms`
237-
- `test3.jpg` (25 faces): pass1 `856 ms`, pass2 `687 ms`
241+
Reference GPU benchmark (AU included, batch_size=8, utilizers disabled, default runtime):
242+
- `test.jpg` (4 faces): pass1 `688 ms`, pass2 `216 ms`, pass3 `311 ms`, warm avg (pass2+pass3) `263 ms`
243+
- `test3.jpg` (25 faces): pass1 `904 ms`, pass2 `745 ms`, pass3 `728 ms`, warm avg (pass2+pass3) `737 ms`
244+
245+
Full FaceAnalyzer artifact comparison (detector + predictors `embed`, `verify`, `fer`, `au`, `va`, `deepfake`, `align`):
246+
- benchmark method: 12 passes/image, report warm median over passes 3-12
247+
248+
| image | faces | all `.pt2` median (default JIT) | all `.pt2` median (TS stability flags) | all TorchScript `.pt` median (TS stability flags) | delta TorchScript - `.pt2` (same flags) |
249+
| --- | ---: | ---: | ---: | ---: | ---: |
250+
| `test.jpg` | 4 | `152.8 ms` | `151.2 ms` | `147.1 ms` | `-4.0 ms` |
251+
| `test3.jpg` | 25 | `525.9 ms` | `520.4 ms` | `518.8 ms` | `-1.6 ms` |
252+
253+
CPU full-stack comparison (8 passes/image, warm median over passes 3-8, `torch_num_threads=16`):
254+
255+
| image | faces | all `.pt2` median | all TorchScript `.pt` median | delta TorchScript - `.pt2` |
256+
| --- | ---: | ---: | ---: | ---: |
257+
| `test.jpg` | 4 | `3080.0 ms` | `2796.5 ms` | `-283.5 ms` |
258+
| `test3.jpg` | 25 | `15945.5 ms` | `14727.6 ms` | `-1217.9 ms` |
238259

239260
Environment used for this benchmark:
240261
- GPU: `NVIDIA GeForce RTX 3090`
241262
- Python: `3.10.12`
242263
- Torch: `2.11.0+cu130`
243264

244265
Method notes:
245-
- Timings are reported from the second inference pass to avoid first-pass warm-up effects.
266+
- Reference GPU timings include pass-level values; artifact comparisons use warm medians to avoid first-pass warm-up effects.
246267
- Timings above include all predictors, including AU.
247268
- Utilizers were disabled for this benchmark run.
269+
- Full TorchScript CUDA comparison required disabling TorchScript profiling/fuser paths for runtime stability (`_jit_set_profiling_executor(False)`, `_jit_set_profiling_mode(False)`, `_jit_override_can_fuse_on_gpu(False)`).
270+
- In this setup, TorchScript is only slightly faster in warm median (about 2-4 ms, <2%); treat this as near-parity rather than a large format-level difference.
271+
- On CPU, TorchScript was faster by about 8-9% for this full-stack run.
272+
- TorchScript shows much slower first pass on some runs (runtime graph specialization), so use warm metrics for fair comparison.
248273
- One can monitor component timings in logs using DEBUG level.
249274

250275

@@ -279,7 +304,7 @@ For broader PyTorch compatibility, publish recommended version cohorts in the sa
279304
- `model-torch2.11.pt2`
280305
- (optional compatibility fallback) `model.pt2`
281306

282-
To export, validate, and upload all facetorch model cohorts for the current torch runtime, use:
307+
From a source checkout, export, validate, and upload all facetorch model cohorts for the current torch runtime with:
283308

284309
```bash
285310
PYTHONPATH=. python scripts/export_model_cohorts_hf.py export \
@@ -304,6 +329,8 @@ PYTHONPATH=. python scripts/export_model_cohorts_hf.py validate \
304329
```
305330

306331
Use `--model-ids` (for example `--model-ids verify-magface`) to process only a subset.
332+
The script writes a `.meta.json` file next to each artifact and fails the run if validated outputs exceed the configured numerical tolerances.
333+
Export-only architecture definitions live in `model_defs/`; they are included for reproducible re-exporting, but they are not required for normal `.pt2` inference.
307334

308335
#### Configuration
309336
##### Create yaml file
@@ -342,6 +369,7 @@ the requirements of the new model.
342369
* `pyproject.toml` is the packaging source of truth for PyPI releases and pip/uv installs (including Docker build paths using uv).
343370
* Conda package publishing (`conda-forge/facetorch`) is maintained outside this repository in conda-forge feedstock workflows.
344371
* `environment.yml` and `gpu.environment.yml` are conda environment baselines for conda users.
372+
* The GPU conda baseline uses conda-forge `cuda-version=12.4` instead of `cudatoolkit`; pass `--with-cuda` when regenerating the GPU lock so conda-lock can resolve CUDA virtual packages without requiring a local GPU.
345373
* Overlapping dependencies between pyproject and conda env files are intentionally kept aligned.
346374
* CI enforces this with: `python scripts/check_dependency_sync.py`.
347375

@@ -353,13 +381,13 @@ the requirements of the new model.
353381
#### conda (for conda-forge users)
354382
CPU:
355383
* Add packages with corresponding versions to ```environment.yml``` file
356-
* Lock the environment: ```conda lock -p linux-64 -f environment.yml --lockfile conda-lock.yml```
384+
* Lock the environment: ```conda-lock -p linux-64 -f environment.yml --lockfile conda-lock.yml```
357385
* (Alternative Docker) Lock the environment: ```docker compose -f docker-compose.dev.yml run facetorch-lock```
358386
* Install the locked environment: ```conda-lock install --name env conda-lock.yml```
359387

360388
GPU:
361389
* Add packages with corresponding versions to ```gpu.environment.yml``` file
362-
* Lock the environment: ```conda lock -p linux-64 -f gpu.environment.yml --lockfile gpu.conda-lock.yml```
390+
* Lock the environment: ```conda-lock --with-cuda 12.4 -p linux-64 -f gpu.environment.yml --lockfile gpu.conda-lock.yml```
363391
* (Alternative Docker) Lock the environment: ```docker compose -f docker-compose.dev.yml run facetorch-lock-gpu```
364392
* Install the locked environment: ```conda-lock install --name env gpu.conda-lock.yml```
365393

0 commit comments

Comments
 (0)