Skip to content

docs: add AGENTS.md with T4/LASER encoder notes - #169

Open
moduvoice wants to merge 2 commits into
facebookresearch:mainfrom
moduvoice:docs/t4-turing-notes
Open

docs: add AGENTS.md with T4/LASER encoder notes#169
moduvoice wants to merge 2 commits into
facebookresearch:mainfrom
moduvoice:docs/t4-turing-notes

Conversation

@moduvoice

Copy link
Copy Markdown

Motivation

While reproducing the mining pipeline's embed_text (LASER sentence encoder) step on a real NVIDIA Tesla T4 (16GB), I ran into a few undocumented gotchas that aren't obvious from the README/configs alone. This PR documents them (no code changes) so the next person hitting them doesn't have to rediscover them from scratch.

Changes

Adds a new AGENTS.md with three notes, all verified against the current code/behavior:

  1. Install: pip install -e '.[mining]' pulls in numpy==2.2.6, which breaks the numpy/torch interop for torch 2.0.x (_ARRAY_API not found). Needs pip install numpy==1.26.4 afterward to fix.
  2. embed_text=laser3 (Transformer) crashes on torch>=2.0: RuntimeError: Mask Type should be defined, caused by fairseq 0.12.2's fused BetterTransformer fastpath being incompatible with torch 2.0's kernel signature. embed_text=laser2 (LSTM, the demo default) is unaffected and runs fine.
  3. fp16_model flag is dead code for the LASER text encoder: it's accepted by LaserSentenceEncoder.__init__ and exposed in laser3_encoder.yaml, but never read in the constructor body or forwarded to SentenceEncoder — so setting it has no effect, and the encoder always runs fp32 on GPU. Manually forcing fp16 (.half()) on the T4 gave a measured 3.23x speedup (1.4938s → 0.4622s for the same 3000-sentence batch) with identical output (cosine similarity 1.0 vs the fp32 baseline). Interestingly, the speech-encoder configs already default fp16_model: True, suggesting this was meant to work for text too but the wiring is missing.

No default behavior, config defaults, or code paths are changed — this is purely documentation of current, verified behavior. The underlying code issues (wiring fp16_model through, and the laser3/torch2 fastpath incompatibility) are separate code-logic fixes I'm not proposing here; happy to file issues for those if useful.

Testing

All three items were reproduced end-to-end on a real Tesla T4 (16GB, driver 550.163.01, CUDA 12.4 runtime, torch 2.0.1+cu118, fairseq 0.12.2, stopes @ current main):

  • Confirmed numpy==2.2.6 gets installed by .[mining] and breaks torch.Tensor.numpy(); confirmed numpy==1.26.4 restores interop.
  • Reproduced the laser3 crash verbatim on first run; confirmed laser2 runs correctly out of the box.
  • Confirmed via grep that fp16_model is never referenced in LaserSentenceEncoder's body, only in the constructor signature and configs.
  • Benchmarked fp32 vs. manually-forced fp16 (3 iterations each, cuda.synchronize()-gated timing) on the same 3000-sentence input, and compared output embeddings by cosine similarity.
  • Confirmed genuine GPU utilization throughout (not silently falling back to CPU): nvidia-smi showed sustained 100% utilization and ~1.8GB VRAM during encoding, vs. a ~15x slower CPU-only run for the same batch.

@meta-cla

meta-cla Bot commented Jul 10, 2026

Copy link
Copy Markdown

Hi @moduvoice!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant