| 826 | } |
| 827 | |
| 828 | bool session_token(const WeightTable& tables, const ModelGeometry& g, int64_t pos, int32_t pos_base, |
| 829 | SessionState& s, const float* parts, void* stream, bool sync_every_layer, |
| 830 | std::string& err) { |
| 831 | cudaStream_t cs = (cudaStream_t) stream; |
| 832 | int64_t qsa_index = 0; |
| 833 | int64_t gdn_index = 0; |
| 834 | |
| 835 | for (int64_t l = 0; l < g.n_layers; ++l) { |
| 836 | // THE GDN LAYERS EACH GET THEIR OWN STATE, and `GdnBuffers` carries it - so the session points the |
| 837 | // shared scratch at the right slice before each call. Sharing one state across 36 layers would make |
| 838 | // every layer start from the previous layer's recurrence, which produces a perfectly finite answer. |
| 839 | if (!is_qsa_layer(g, l)) { |
| 840 | s.gdn.state = s.gdn_state + (size_t) gdn_index * gdn_state_floats(g); |
| 841 | s.gdn.conv_state = s.gdn.state + (uint64_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size; |
| 842 | ++gdn_index; |
| 843 | } |
| 844 | |
| 845 | err.clear(); |
| 846 | const bool ok = is_qsa_layer(g, l) |
| 847 | ? block_layer(tables, g, l, pos, pos_base, s.gdn, s.qsa_states[qsa_index], s.qsa_bufs, s.moe, s.k, |
| 848 | s.block, parts, stream, err, nullptr, s.ple.ready() ? &s.ple : nullptr) |
| 849 | : block_layer(tables, g, l, pos, pos_base, s.gdn, s.qsa_states[0], s.qsa_bufs, s.moe, s.k, |
| 850 | s.block, parts, stream, err, nullptr, s.ple.ready() ? &s.ple : nullptr); |
| 851 | if (!ok) { |
| 852 | err = "layer " + std::to_string(l) + ": " + err; |
| 853 | return false; |
| 854 | } |
| 855 | if (is_qsa_layer(g, l)) ++qsa_index; |
| 856 | |
| 857 | if (sync_every_layer) { |
| 858 | // THE DEBUG MODE, and its cost is the point: it is a real synchronisation after every layer, which |
| 859 | // P2.X3 forbids in the fast path. It exists to turn an ASYNCHRONOUS error - a kernel reading a |
| 860 | // buffer a later layer wrote, or an out-of-range launch - into a failure AT THE LAYER THAT CAUSED |
| 861 | // IT, instead of a wrong number 40 layers later or at the end of the token. |
| 862 | const cudaError_t e = cudaStreamSynchronize(cs); |
| 863 | if (e != cudaSuccess) { |
| 864 | err = "layer " + std::to_string(l) + ": " + cudaGetErrorString(e); |
| 865 | return false; |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | return true; |
| 870 | } |
| 871 | |
| 872 | } // namespace strata::core |
| 873 |
nothing calls this directly
no test coverage detected