@@ -153,24 +153,34 @@ AttentionImpl GetAttentionImpl(const std::string& impl);
153153enum class PostNormType {
154154 None,
155155 Scale,
156- kSentinel // must be last
157156};
158157
159158static inline bool EnumValid (PostNormType type) {
160- return static_cast <size_t >(type) <
161- static_cast <size_t >(PostNormType::kSentinel );
159+ switch (type) {
160+ case PostNormType::None:
161+ case PostNormType::Scale:
162+ return true ;
163+ default :
164+ return false ;
165+ }
162166}
163167
164168// Post qk projection operation type.
165169enum class PostQKType {
166170 Rope,
167171 HalfRope,
168172 NormLocalRope = 8 , // Norm without scale, and rope for local attention layers
169- kSentinel // must be last
170173};
171174
172175static inline bool EnumValid (PostQKType type) {
173- return static_cast <size_t >(type) < static_cast <size_t >(PostQKType::kSentinel );
176+ switch (type) {
177+ case PostQKType::Rope:
178+ case PostQKType::HalfRope:
179+ case PostQKType::NormLocalRope:
180+ return true ;
181+ default :
182+ return false ;
183+ }
174184}
175185
176186// FFW activation function.
@@ -215,12 +225,15 @@ static inline bool EnumValid(QueryScaleType type) {
215225// Residual connection type.
216226enum class ResidualType {
217227 Add,
218- kSentinel // must be last
219228};
220229
221230static inline bool EnumValid (ResidualType type) {
222- return static_cast <size_t >(type) <
223- static_cast <size_t >(ResidualType::kSentinel );
231+ switch (type) {
232+ case ResidualType::Add:
233+ return true ;
234+ default :
235+ return false ;
236+ }
224237}
225238
226239template <size_t kNum >
@@ -314,6 +327,8 @@ void ForEachModel(const Func& func) {
314327 }
315328}
316329
330+ static inline bool IsInternal (Model model) { return false ; }
331+
317332static inline bool EnumValid (Model model) {
318333 // Valid for purposes of serialization, even if unknown.
319334 if (model == Model::UNKNOWN ) return true ;
@@ -360,7 +375,7 @@ struct LayerConfig : public IFields {
360375 visitor (activation);
361376 visitor (post_qk);
362377 visitor (use_qk_norm);
363- internal. VisitFields (visitor);
378+ // Visiting includes size prefix, whereas calling VisitFields would inline.
364379 visitor (norm_v);
365380 visitor (num_experts);
366381 visitor (num_experts_per_datapoint);
@@ -611,7 +626,7 @@ struct ModelConfig : public IFields {
611626
612627 visitor (scale_base_names);
613628
614- internal. VisitFields (visitor);
629+ // Visiting includes size prefix, whereas calling VisitFields would inline.
615630
616631 visitor (use_global_timescale);
617632 visitor (partial_rotary_factor);
0 commit comments