Repository navigation
v0.8.10
End-to-end fixes for the section 15 fine-tuning pipeline. The pipeline failed at multiple points; this release fixes them in sequence so the notebooks run from a fresh clone.
Fixed
- `15-fine-tune/15-01-data-preparation.ipynb` failed at cell 3 with `ModuleNotFoundError: No module named 'torch'`. Two underlying issues: (1) `torch`, `transformers`, `peft`, `matplotlib`, `azure-storage-blob`, and `azure-ai-inference` were never declared in `pyproject.toml`, and (2) cell 2's inline `%pip install` silently failed in the uv-managed `.venv` (which doesn't ship `pip`, so `%pip` prints `No module named pip`). Same import-failure pattern would have hit `15-04-local-inference.ipynb`, which depends on torch/transformers/peft but had no install cell at all.
- `15-fine-tune/15-01-data-preparation.ipynb` cell 8 then failed with `OpenAIError: Missing credentials` because `FINETUNE_GATEWAY_KEY` was missing from `.env`. The Bicep at `15-fine-tune/main.bicep` does not create a dedicated `foundry-gateway-finetune` APIM subscription (unlike 10-01 / 11-01 which provision their own), so this env var was never going to be set. The teacher-model call only needs any valid APIM key, so the cell now reuses `ALPHA_GATEWAY_KEY` (already in `.env` from the project-spoke deployment). This removes a phantom env variable and one redundant Azure resource.
- `15-fine-tune/15-02-fine-tune.ipynb` ACA job failed with `The specified resource name length is not within the permissible limits`. Container name `"ft"` violated Azure Storage's 3-63 character minimum. The container creation silently failed (because the helper used `check=False`), then the in-job blob download from `"ft"` errored visibly. Renamed to `"finetune"` in 15-02 / 15-03 / 15-04 cell-3 constants and in `15-fine-tune/main.bicep` (which had the same bug). `azure_infra.py` takes the name as a parameter so no source change there.
- `15-fine-tune/15-03-evaluate.ipynb` raised `NameError: name 'eval_dataset' is not defined` when run in a fresh kernel. It implicitly relied on `eval_dataset` / `reports_data` / `env_id` / `accuracy` being in memory from 15-01 + 15-02. Cell 3 now re-derives all four: `eval_dataset` via `iss_utils.get_evaluation_dataset()`, `reports_data` via NASA fetch (~30s), `env_id` via `az containerapp env show`, and fallback teacher/base accuracies with comments explaining how to override. Also added `import pandas as pd` and `from IPython.display import display` to the imports cell (previously caused `NameError: pd not defined` in the comparison cell) and fixed an outdated `"DeepSeek-V3.2 (Teacher)"` label in the summary table to match the actual teacher (`gpt-4.1-mini`) used throughout the chain.
- `15-fine-tune/15-04-local-inference.ipynb` failed with `ImportError: cannot import name 'LossKwargs' from transformers.utils`. Phi-4-mini's custom remote modeling code (`modeling_phi3.py` from the Hugging Face hub) imports symbols (`LossKwargs`, etc.) that were removed in transformers 5.x. The `[finetune]` dep group's `transformers>=4.40.0` constraint allowed 5.x to be pulled in. Tightened to `>=4.46.0,<5.0.0` with a comment explaining the upper bound; matches the `transformers==4.53.3` pin the ACA fine-tune job uses inline.
- `15-fine-tune/15-04-local-inference.ipynb` `generate()` emitted a "The attention mask is not set and cannot be inferred" warning because `apply_chat_template` returned just the input_ids tensor and Phi-4-mini has `pad_token == eos_token`. Reworked to use `apply_chat_template(..., return_dict=True)` and pass `**inputs` to `generate()` so both `input_ids` and `attention_mask` are present.
Added
- New `[dependency-groups] finetune` entry in `pyproject.toml` declaring the heavy ML dependencies needed for section 15. Users run `uv sync --group finetune` once before opening section 15. Base install stays lean for everyone else (~3 GB saved when section 15 isn't needed). Matches the pattern used for `azure-ai-evaluation[redteam]` in section 14.
- Committed `15-fine-tune/data/train.jsonl` (100-example synthetic+real distillation training set generated against the gpt-4.1-mini teacher). Useful as a fixed artifact so 15-02 can be re-run without regenerating the data (saves ~200 teacher calls), and readers can inspect what the LoRA trains on.
- New entries in `.gitignore` for section 15 artifacts that should not be committed by accident: `15-fine-tune/data/`, `15-fine-tune/models/` (~350MB of LoRA adapter weights), `15-fine-tune/eval_job.json`, and `15-fine-tune/job.json` (contain real subscription IDs when written by local runs).
Changed
- Cell 2 of `15-01-data-preparation.ipynb` converted from a broken `%pip install` code cell to a markdown cell that points readers at the `uv sync --group finetune` command and explains why `%pip` doesn't work in this venv.
- Updated `15-00-fine-tune.md` prerequisites to specify `uv sync --group finetune` and reference `ALPHA_GATEWAY_KEY` (no separate `FINETUNE_GATEWAY_KEY`).
- Reduced default `TARGET_TOTAL` in `15-01` from 500 to 100 (demo-sized, ~200 teacher calls), with a rationale block above the constant and an expanded markdown header pointing readers at the literature's 500-2000 sweet spot for narrow classification distillation.