[bugfix] fix flaky TRT predict test by making the mock model confident - #549
Conversation
d33adbb to
54ee605
Compare
| self.success = utils.test_train_eval( | ||
| pipeline_config_path, | ||
| self.test_dir, | ||
| user_id="user_id", | ||
| item_id="item_id", | ||
| learnable_label="raw_1", | ||
| num_epochs=3, | ||
| ) |
There was a problem hiding this comment.
The fix is well-reasoned, but it can silently self-disable: the encoding in create_mock_join_data is guarded by learnable_label in t.column_names (utils.py:558), so if raw_1 is ever renamed/dropped from these configs the encoding is skipped, the model trains on random labels again, and this test quietly reverts to the exact flaky state it was meant to fix — with no failure signal, since nothing asserts the model became confident (only 2e-5 closeness + file existence are checked).
Consider adding a cheap confidence assertion to lock in the premise the whole fix rests on, e.g. after eval, assert the predicted probs are bimodal (((probs < 0.05) | (probs > 0.95)).mean() > 0.9) or assert the AUC in train/eval_result.txt is high. That turns a silent regression into a loud one and also answers "is num_epochs=3 always enough?" on every run.
| for label_field in label_fields: | ||
| input_data[label_field] = pa.array(np.random.randint(2, size=(num_rows,))) | ||
| label = np.random.randint(2, size=(num_rows,)) | ||
| input_data[label_field] = pa.array(label) | ||
| if learnable_label and learnable_label in input_data: | ||
| input_data[learnable_label] = _learnable_label_value(label) |
There was a problem hiding this comment.
Minor/optional: this encodes inside the label loop keyed to the loop's last label, whereas create_mock_join_data keys to label_fields[0] (line 558-559). Harmless for the current single-label (clk) configs, but the two helpers would diverge for a multi-label test. Suggest hoisting it out of the loop and keying to a single explicit label for consistency:
for label_field in label_fields:
input_data[label_field] = pa.array(np.random.randint(2, size=(num_rows,)))
if learnable_label and label_fields and learnable_label in input_data:
label = input_data[label_fields[0]].to_numpy(zero_copy_only=False)
input_data[learnable_label] = _learnable_label_value(label)|
Review summary — test-only change; LGTM in substance. Nicely diagnosed and documented: fixing the ill-conditioning at the source (confident model) instead of loosening the Two non-blocking suggestions left inline:
|
The random-label mock fixture trains to logit~=0 everywhere (prob~=0.5), an ill-conditioned regime where TRT's tiny per-process GEMM-reduction nondeterminism (~1e-7 at the fp32 accumulator) is amplified into ~1e-3 prob swings on decision-boundary rows, flaking the strict TRT-vs-baseline compare in _test_rank_with_fg_trt. It is a degenerate-fixture artifact, not a TRT correctness bug -- eager and TRT compute the same function. Fix at the source instead of loosening tolerance: test_train_eval gains learnable_label (encode the label bimodally into a raw feature, cleanly separable across bucketize bins) and num_epochs. The TRT tests encode into raw_1 and train 3 epochs, so the model drives |logit| large; eager and TRT then agree to the fp32 floor (~1e-7) and the strict 2e-5 compare is stable. Default behavior (random labels) is unchanged for all other tests. Verified: 240 separate-process launches per config, worst atol 1.8e-7 (custom_1 AutoDis) / 4.8e-7 (bucketized) << 2e-5 (was 3.6e-4 / 1.2e-3); both the plain and zch TRT tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CyvX3iUqQzvM6XuQPyMtG8
54ee605 to
24323d2
Compare
Problem
test_multi_tower_with_fg_train_eval_export_trt(and the_zchvariant) flake: the strict TRT-vs-baseline comparison in_test_rank_with_fg_trtoccasionally fails by ~1e-3 prob on a few rows.Root cause
The mock fixture trains on random labels, so the model can't learn and every logit ≈ 0 (prob ≈ 0.5). That is a maximally ill-conditioned regime (κ ≈ 1e5): TRT's tiny per-process GEMM-reduction nondeterminism (~1e-7 at the fp32 accumulator) gets amplified into ~1e-3 prob swings on these decision-boundary rows. It is a degenerate-fixture artifact, not a TRT correctness bug — eager and TRT compute the same function (they agree to ~1e-7 once logits are confident).
Fix
Make the model confident rather than loosening the tolerance.
test_train_evalgains two optional, default-off params:learnable_label— encodes the label bimodally into a raw feature (0 → ~0.05,1 → ~0.95), which lands in distinct bucketize bins with a clear gap, so the signal is cleanly separable.num_epochs— lets a test train enough to fit it.The TRT tests encode into
raw_1and train 3 epochs. The model then drives|logit|large, eager and TRT agree to the fp32 floor (~1e-7), and the strict2e-5comparison is stable. Default behavior (random labels, original epochs) is unchanged for every other test.Verification
2e-5— vs 3.6e-4 / 1.2e-3 unfixed.test_multi_tower_with_fg_train_eval_export_trtandtest_multi_tower_zch_with_fg_train_eval_export_trtpass locally.🤖 Generated with Claude Code