diff --git a/gemma/configs.h b/gemma/configs.h index 7e9f62f1..cb897ef7 100644 --- a/gemma/configs.h +++ b/gemma/configs.h @@ -153,12 +153,16 @@ AttentionImpl GetAttentionImpl(const std::string& impl); enum class PostNormType { None, Scale, - kSentinel // must be last }; static inline bool EnumValid(PostNormType type) { - return static_cast(type) < - static_cast(PostNormType::kSentinel); + switch (type) { + case PostNormType::None: + case PostNormType::Scale: + return true; + default: + return false; + } } // Post qk projection operation type. @@ -166,11 +170,17 @@ enum class PostQKType { Rope, HalfRope, NormLocalRope = 8, // Norm without scale, and rope for local attention layers - kSentinel // must be last }; static inline bool EnumValid(PostQKType type) { - return static_cast(type) < static_cast(PostQKType::kSentinel); + switch (type) { + case PostQKType::Rope: + case PostQKType::HalfRope: + case PostQKType::NormLocalRope: + return true; + default: + return false; + } } // FFW activation function. @@ -215,12 +225,15 @@ static inline bool EnumValid(QueryScaleType type) { // Residual connection type. enum class ResidualType { Add, - kSentinel // must be last }; static inline bool EnumValid(ResidualType type) { - return static_cast(type) < - static_cast(ResidualType::kSentinel); + switch (type) { + case ResidualType::Add: + return true; + default: + return false; + } } template @@ -314,6 +327,8 @@ void ForEachModel(const Func& func) { } } +static inline bool IsInternal(Model model) { return false; } + static inline bool EnumValid(Model model) { // Valid for purposes of serialization, even if unknown. if (model == Model::UNKNOWN) return true; @@ -360,7 +375,7 @@ struct LayerConfig : public IFields { visitor(activation); visitor(post_qk); visitor(use_qk_norm); - internal.VisitFields(visitor); + // Visiting includes size prefix, whereas calling VisitFields would inline. visitor(norm_v); visitor(num_experts); visitor(num_experts_per_datapoint); @@ -611,7 +626,7 @@ struct ModelConfig : public IFields { visitor(scale_base_names); - internal.VisitFields(visitor); + // Visiting includes size prefix, whereas calling VisitFields would inline. visitor(use_global_timescale); visitor(partial_rotary_factor);