@@ -769,54 +769,63 @@ std::string common_sampler_type_to_str(enum common_sampler_type cnstr) {
769769 }
770770}
771771
772- std::vector<common_sampler_type> common_sampler_types_from_names (const std::vector<std::string> & names, bool allow_alt_names) {
773- std::unordered_map<std::string, common_sampler_type> sampler_canonical_name_map {
774- { " dry" , COMMON_SAMPLER_TYPE_DRY },
775- { " top_k" , COMMON_SAMPLER_TYPE_TOP_K },
776- { " top_p" , COMMON_SAMPLER_TYPE_TOP_P },
777- { " top_n_sigma" , COMMON_SAMPLER_TYPE_TOP_N_SIGMA },
778- { " typ_p" , COMMON_SAMPLER_TYPE_TYPICAL_P },
779- { " min_p" , COMMON_SAMPLER_TYPE_MIN_P },
780- { " temperature" , COMMON_SAMPLER_TYPE_TEMPERATURE },
781- { " xtc" , COMMON_SAMPLER_TYPE_XTC },
782- { " infill" , COMMON_SAMPLER_TYPE_INFILL },
783- { " penalties" , COMMON_SAMPLER_TYPE_PENALTIES },
784- { " adaptive_p" , COMMON_SAMPLER_TYPE_ADAPTIVE_P },
785- };
786-
787- // since samplers names are written multiple ways
788- // make it ready for both system names and input names
789- std::unordered_map<std::string, common_sampler_type> sampler_alt_name_map {
790- { " top-k" , COMMON_SAMPLER_TYPE_TOP_K },
791- { " top-p" , COMMON_SAMPLER_TYPE_TOP_P },
792- { " top-n-sigma" , COMMON_SAMPLER_TYPE_TOP_N_SIGMA },
793- { " nucleus" , COMMON_SAMPLER_TYPE_TOP_P },
794- { " typical-p" , COMMON_SAMPLER_TYPE_TYPICAL_P },
795- { " typical" , COMMON_SAMPLER_TYPE_TYPICAL_P },
796- { " typ-p" , COMMON_SAMPLER_TYPE_TYPICAL_P },
797- { " typ" , COMMON_SAMPLER_TYPE_TYPICAL_P },
798- { " min-p" , COMMON_SAMPLER_TYPE_MIN_P },
799- { " temp" , COMMON_SAMPLER_TYPE_TEMPERATURE },
800- { " adaptive-p" , COMMON_SAMPLER_TYPE_ADAPTIVE_P },
801- };
772+ std::vector<common_sampler_type> common_sampler_types_from_names (const std::vector<std::string> & names) {
773+ // sampler names can be written multiple ways; generate aliases from canonical names
774+ static const auto sampler_name_map = []{
775+ // canonical sampler name mapping
776+ std::unordered_map<std::string, common_sampler_type> canonical_name_map {
777+ { " dry" , COMMON_SAMPLER_TYPE_DRY },
778+ { " top_k" , COMMON_SAMPLER_TYPE_TOP_K },
779+ { " top_p" , COMMON_SAMPLER_TYPE_TOP_P },
780+ { " top_n_sigma" , COMMON_SAMPLER_TYPE_TOP_N_SIGMA },
781+ { " typ_p" , COMMON_SAMPLER_TYPE_TYPICAL_P },
782+ { " min_p" , COMMON_SAMPLER_TYPE_MIN_P },
783+ { " temperature" , COMMON_SAMPLER_TYPE_TEMPERATURE },
784+ { " xtc" , COMMON_SAMPLER_TYPE_XTC },
785+ { " infill" , COMMON_SAMPLER_TYPE_INFILL },
786+ { " penalties" , COMMON_SAMPLER_TYPE_PENALTIES },
787+ { " adaptive_p" , COMMON_SAMPLER_TYPE_ADAPTIVE_P }
788+ };
789+ std::unordered_map<std::string, common_sampler_type> alias_name_map;
790+ for (const auto & entry : canonical_name_map) {
791+ const std::string & canonical = entry.first ;
792+ if (canonical.find (' _' ) == std::string::npos) {
793+ continue ;
794+ }
795+ // kebab-case: "top-k", "min-p", etc.
796+ {
797+ std::string kebab_case = canonical;
798+ std::replace (kebab_case.begin (), kebab_case.end (), ' _' , ' -' );
799+ alias_name_map.insert ({kebab_case, entry.second });
800+ }
801+ // no dash: "topk", "minp", etc.
802+ {
803+ std::string no_dash = canonical;
804+ no_dash.erase (std::remove (no_dash.begin (), no_dash.end (), ' _' ), no_dash.end ());
805+ alias_name_map.insert ({no_dash, entry.second });
806+ }
807+ }
808+ // misc. aliases
809+ alias_name_map.insert ({" nucleus" , COMMON_SAMPLER_TYPE_TOP_P });
810+ alias_name_map.insert ({" temp" , COMMON_SAMPLER_TYPE_TEMPERATURE });
811+ alias_name_map.insert ({" typ" , COMMON_SAMPLER_TYPE_TYPICAL_P });
812+ // include aliases + canonical names in the complete mapping
813+ alias_name_map.merge (canonical_name_map);
814+ return alias_name_map;
815+ }();
802816
803817 std::vector<common_sampler_type> samplers;
804818 samplers.reserve (names.size ());
805819
806820 for (const auto & name : names) {
807- auto sampler = sampler_canonical_name_map.find (name);
808- if (sampler != sampler_canonical_name_map.end ()) {
821+ std::string name_lower = name;
822+ std::transform (name_lower.begin (), name_lower.end (), name_lower.begin (), ::tolower);
823+ auto sampler = sampler_name_map.find (name_lower);
824+ if (sampler != sampler_name_map.end ()) {
809825 samplers.push_back (sampler->second );
810826 continue ;
811827 }
812- if (allow_alt_names) {
813- sampler = sampler_alt_name_map.find (name);
814- if (sampler != sampler_alt_name_map.end ()) {
815- samplers.push_back (sampler->second );
816- continue ;
817- }
818- }
819- LOG_WRN (" %s: unable to match sampler by name '%s'\n " , __func__, name.c_str ());
828+ LOG_WRN (" %s: unable to match sampler by name '%s'\n " , __func__, name_lower.c_str ());
820829 }
821830
822831 return samplers;
0 commit comments