MCPcopy
hub / github.com/sammcj/gollama / ParseBPWOrQuant

Function ParseBPWOrQuant

vramestimator/vramestimator.go:663–692  ·  view source on GitHub ↗

parseBPWOrQuant takes a string and returns a float64 BPW value

(input string)

Source from the content-addressed store, hash-verified

661
662// parseBPWOrQuant takes a string and returns a float64 BPW value
663func ParseBPWOrQuant(input string) (float64, error) {
664 // First, try to parse as a float64 (direct BPW value)
665 bpw, err := strconv.ParseFloat(input, 64)
666 if err == nil {
667 return bpw, nil
668 }
669
670 // If parsing as float fails, check if it's a valid quantisation type
671 input = strings.ToUpper(input) // Convert to uppercase for case-insensitive matching
672 if bpw, ok := GGUFMapping[input]; ok {
673 return bpw, nil
674 }
675
676 // If not found, try to find a close match
677 var closestMatch string
678 var minDistance int = len(input)
679 for key := range GGUFMapping {
680 distance := levenshteinDistance(input, key)
681 if distance < minDistance {
682 minDistance = distance
683 closestMatch = key
684 }
685 }
686
687 if closestMatch != "" {
688 return 0, fmt.Errorf("invalid quantisation type: %s. Did you mean %s?", input, closestMatch)
689 }
690
691 return 0, fmt.Errorf("invalid quantisation or BPW value: %s", input)
692}
693
694// levenshteinDistance calculates the Levenshtein distance between two strings
695func levenshteinDistance(s1, s2 string) int {

Callers 1

CalculateVRAMFunction · 0.85

Calls 1

levenshteinDistanceFunction · 0.85

Tested by

no test coverage detected