Worker function for TP2 greedy tests (passed to run_maybe_distributed).
()
| 188 | chi_squared, p_value = chisquare(obs, exp) |
| 189 | degrees_of_freedom = len(obs) - 1 |
| 190 | reduced_chi_squared = chi_squared / degrees_of_freedom |
| 191 | if print_result: |
| 192 | print( |
| 193 | f"Chi-squared: provider={provider}, V={vocab_size}, H={n_hidden_states}, " |
| 194 | f"samples={num_samples}, tested_bins={mask.sum()}, " |
| 195 | f"tested_probability_mass={tested_probability_mass:.6f}, " |
| 196 | f"statistic={chi_squared:.3f}, df={degrees_of_freedom}, " |
| 197 | f"reduced_statistic={reduced_chi_squared:.6f}, p={p_value:.6g}" |
| 198 | ) |
| 199 | assert not np.isnan(p_value), ( |
| 200 | f"Chi-squared returned NaN for seq {seq_idx} — likely all samples " |
| 201 | f"landed in a single tile. {provider} may have a masked-fill bug." |
| 202 | ) |
| 203 | assert p_value > 0.001, ( |
| 204 | f"Sampling distribution mismatch for seq {seq_idx}: p={p_value:.6f}. " |
| 205 | f"{provider} does not match the expected softmax distribution." |
| 206 | ) |
| 207 | |
| 208 | |
| 209 | def assert_sampling_distribution_large_vocab( |
| 210 | vocab_size: int = 32_768, |
| 211 | num_samples: int = 1_000_000, |
no test coverage detected