Skip to content

fix(train): load_dotenv override=True so empty devcontainer forwards lose to .env - #11

Merged
tkgstrator merged 1 commit into
developfrom
fix/dotenv-override
Jul 13, 2026
Merged

fix(train): load_dotenv override=True so empty devcontainer forwards lose to .env#11
tkgstrator merged 1 commit into
developfrom
fix/dotenv-override

Conversation

@tkgstrator

Copy link
Copy Markdown
Contributor

What

Change the three training entrypoints (train_board_ocr.py, train_piece.py, train_detector.py) to call load_dotenv(override=True). Bumps pyproject.toml to 0.3.2.

Why

.devcontainer/**/devcontainer.json forwards ${localEnv:HF_TOKEN} and ${localEnv:WANDB_API_KEY}. When those vars are not exported on the host they expand to an empty string, which the devcontainer sets on the container's environment. load_dotenv() with the default override=False sees the key as "already set" (even though the value is "") and refuses to import from .env. Result: HF calls run unauthenticated and wandb init logs WANDB_API_KEY not set, skipping even though the token is in .env.

With override=True, .env wins over empty forwards. Real host values still flow through if present — override just replaces empties too.

Test plan

  • Repro'd the empty-string skip and confirmed override=True resolves both HF_TOKEN and WANDB_API_KEY
  • Re-launch the BoardOCR run and confirm the HF warning disappears and wandb initializes

Version

0.3.10.3.2 (patch — behavior fix)

🤖 Generated with Claude Code

…lose to .env

devcontainer.json forwards ${localEnv:HF_TOKEN} and ${localEnv:WANDB_API_KEY}
from the host, which expand to an empty string when those vars are unset on
the host. load_dotenv() with the default override=False then treats the
empty string as "already set" and refuses to import the value from .env,
leaving HF (unauthenticated) and wandb (skipped) silently broken.

Switch the three training entrypoints (train_board_ocr, train_piece,
train_detector) to load_dotenv(override=True) so .env wins over empty
forwards. Real host values still flow through — override just replaces
empties too.

Bump version to 0.3.2.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tkgstrator
tkgstrator merged commit 7d9526b into develop Jul 13, 2026
3 checks passed
@tkgstrator
tkgstrator deleted the fix/dotenv-override branch July 13, 2026 04:30
tkgstrator added a commit that referenced this pull request Jul 13, 2026
Companion bump for the LR scheduler feature. develop is at 0.3.2 after PR
#11, so this ships the scheduler as the next patch release.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tkgstrator added a commit that referenced this pull request Jul 13, 2026
BoardOCR training previously ran with a constant LR (default 3e-4) for the
full epoch budget, leaving cheap image-classification gains on the table
especially for 200-epoch runs.

Add three CLI flags plumbed into a per-step SequentialLR of LinearLR +
CosineAnnealingLR:

  --scheduler {none,cosine}   default: cosine
  --warmup-epochs INT         default: 5
  --min-lr-ratio FLOAT        default: 0.01   (min_lr = lr * ratio)

The scheduler steps once per batch (all ranks share len(train_loader) shard
size, so DDP stays in lockstep), its state is persisted in the checkpoint,
and current LR is logged to W&B as step/lr each --log-every batch.

--scheduler=none reverts to the prior constant-LR behavior for
back-compat / A/B comparisons.

Note: version bump deferred; PR #11 already bumps to 0.3.2, so whichever
PR merges second will need to re-bump.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tkgstrator added a commit that referenced this pull request Jul 13, 2026
* feat(train): add cosine LR scheduler with linear warmup

BoardOCR training previously ran with a constant LR (default 3e-4) for the
full epoch budget, leaving cheap image-classification gains on the table
especially for 200-epoch runs.

Add three CLI flags plumbed into a per-step SequentialLR of LinearLR +
CosineAnnealingLR:

  --scheduler {none,cosine}   default: cosine
  --warmup-epochs INT         default: 5
  --min-lr-ratio FLOAT        default: 0.01   (min_lr = lr * ratio)

The scheduler steps once per batch (all ranks share len(train_loader) shard
size, so DDP stays in lockstep), its state is persisted in the checkpoint,
and current LR is logged to W&B as step/lr each --log-every batch.

--scheduler=none reverts to the prior constant-LR behavior for
back-compat / A/B comparisons.

Note: version bump deferred; PR #11 already bumps to 0.3.2, so whichever
PR merges second will need to re-bump.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: bump version to 0.3.3

Companion bump for the LR scheduler feature. develop is at 0.3.2 after PR

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tkgstrator tkgstrator mentioned this pull request Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant