MCPcopy Create free account
hub / github.com/antirez/ds4 / test_streaming_decode_prefill_correctness

Function test_streaming_decode_prefill_correctness

tests/ds4_test.c:1663–1776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1661 // so a missing candidate write cannot inherit the reference value.
1662 for (uint64_t i = 0; i < input_count; i++) {
1663 const uint32_t bits = 0x7fc00001u + (uint32_t)(i & 0x3ffu);
1664 memcpy(kv_host + i, &bits, sizeof(bits));
1665 memcpy(sc_host + i, &bits, sizeof(bits));
1666 }
1667 for (uint64_t i = 0; i < state_count; i++) {
1668 const uint32_t bits = 0x7fc00401u + (uint32_t)(i & 0x3ffu);
1669 memcpy(ref_state_kv_host + i, &bits, sizeof(bits));
1670 memcpy(ref_state_score_host + i, &bits, sizeof(bits));
1671 }
1672 TEST_ASSERT(ds4_gpu_tensor_write(kv, 0, kv_host, input_bytes) != 0);
1673 TEST_ASSERT(ds4_gpu_tensor_write(sc, 0, sc_host, input_bytes) != 0);
1674 TEST_ASSERT(ds4_gpu_tensor_write(
1675 fused_state_kv, 0, ref_state_kv_host, state_bytes) != 0);
1676 TEST_ASSERT(ds4_gpu_tensor_write(
1677 fused_state_score, 0, ref_state_score_host,
1678 state_bytes) != 0);
1679 TEST_ASSERT(ds4_gpu_compressor_prefill_ratio4_replay_tensor(
1680 fused_comp, fused_state_kv, fused_state_score, kv, sc,
1681 model_raw, model_bytes, 0, 1, norm_offset, 0,
1682 head_dim, 0, n_tokens, 0, 0, false,
1683 10000.0f, 1.0f, 0.0f, 1.0f, 32.0f, 1.0f, 1.0e-6f) != 0);
1684
1685 // Restore finite sources and the candidate's original replay state.
1686 for (uint64_t i = 0; i < input_count; i++) {
1687 const int kv_value =
1688 (int)((i * 31u + (i ^ (i >> 4u)) * 5u + seed * 13u) %
1689 193u) - 96;
1690 const int sc_value =
1691 (int)((i * 37u + (i ^ (i >> 5u)) * 9u + seed * 17u) %
1692 181u) - 90;
1693 kv_host[i] = (float)kv_value / 104.0f;
1694 sc_host[i] = (float)sc_value / 88.0f;
1695 }
1696 memcpy(kv_host, &negative_zero, sizeof(negative_zero));
1697 TEST_ASSERT(ds4_gpu_tensor_write(kv, 0, kv_host, input_bytes) != 0);
1698 TEST_ASSERT(ds4_gpu_tensor_write(sc, 0, sc_host, input_bytes) != 0);
1699 TEST_ASSERT(ds4_gpu_tensor_write(
1700 fused_state_kv, 0, state_kv_host, state_bytes) != 0);
1701 TEST_ASSERT(ds4_gpu_tensor_write(
1702 fused_state_score, 0, state_score_host,
1703 state_bytes) != 0);
1704 TEST_ASSERT(unsetenv(pack_disable_env) == 0);
1705 TEST_ASSERT(ds4_gpu_compressor_prefill_ratio4_replay_tensor(
1706 fused_comp, fused_state_kv, fused_state_score, kv, sc,
1707 model_raw, model_bytes, 0, 1, norm_offset, 0,
1708 head_dim, 0, n_tokens, 0, 0, false,
1709 10000.0f, 1.0f, 0.0f, 1.0f, 32.0f, 1.0f, 1.0e-6f) != 0);
1710
1711 TEST_ASSERT(ds4_gpu_tensor_read(
1712 kv, 0, source_after_host, input_bytes) != 0);
1713 TEST_ASSERT(memcmp(kv_host, source_after_host,
1714 (size_t)input_bytes) == 0);
1715 TEST_ASSERT(ds4_gpu_tensor_read(
1716 sc, 0, source_after_host, input_bytes) != 0);
1717 TEST_ASSERT(memcmp(sc_host, source_after_host,
1718 (size_t)input_bytes) == 0);
1719 TEST_ASSERT(ds4_gpu_tensor_read(
1720 ref_comp, 0, ref_comp_host, comp_bytes) != 0);

Callers

nothing calls this directly

Calls 11

test_close_enginesFunction · 0.85
test_env_boolFunction · 0.85
test_open_engineFunction · 0.85
test_load_mpp_casesFunction · 0.85
test_mpp_captureFunction · 0.85
ds4_engine_closeFunction · 0.85
test_compare_mpp_logitsFunction · 0.85
test_mpp_eq_case_freeFunction · 0.85

Tested by

no test coverage detected