Skip to content

t6 sentiment: finbert serving behind a protocol, POST /v1/sentiment off the event loop - #1

Merged
vlobus merged 2 commits into
mainfrom
t6-sentiment
Jul 5, 2026
Merged

vlobus merged 2 commits into
mainfrom
t6-sentiment

Conversation

@vlobus

@vlobus vlobus commented Jul 5, 2026

Copy link
Copy Markdown
Owner

what

  • domain/sentiment.pySentimentModel Protocol (the serving seam), pure to_score mapping (argmax label, quantized Decimal probs, rejects wrong label sets / out-of-range values), FinBertModel adapter (ProsusAI/finbert, heavy imports deferred to construction, loaded once).
  • serving/ — FastAPI app factory with DI via app.state, POST /v1/sentiment (label + probs + model_version), GET /health/live. Inference runs on a dedicated single-worker executor: keeps the event loop free, serializes forward passes (no CPU oversubscription), and sidesteps HF fast-tokenizer thread-safety.
  • main.py — composition root: build FinBERT once, serve with uvicorn (python -m hodlin_recommend.main).
  • deps: fastapi, transformers 5.13, torch 2.12, uvicorn.

tests

  • default suite fully offline — a regression guard asserts torch/transformers are never imported.
  • event-gated concurrency test proves the loop serves a liveness ping while an inference is provably in flight (no wall-clock flakiness).
  • opt-in real-model smoke (HODLIN_TEST_FINBERT=1): verified locally — positive/negative texts score correctly through the endpoint, model_version finbert:ProsusAI/finbert.
  • full gate green: ruff, mypy strict, import-linter, pytest (67 passed).

vlobus added 2 commits July 5, 2026 18:47
…ted concurrency test, composition root, literal labels + prob range guard
@vlobus vlobus closed this Jul 5, 2026
@vlobus
vlobus deleted the t6-sentiment branch July 5, 2026 20:32
@vlobus
vlobus restored the t6-sentiment branch July 5, 2026 20:33
@vlobus vlobus reopened this Jul 5, 2026
@vlobus
vlobus merged commit 3293054 into main Jul 5, 2026
2 checks passed
@vlobus
vlobus deleted the t6-sentiment branch July 5, 2026 20:37
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