ollama/llm/filetype.go

141 lines
2.5 KiB
Go
Raw Normal View History

package llm
import "fmt"
2024-04-23 22:18:45 +00:00
type fileType uint32
const (
2024-04-23 22:18:45 +00:00
fileTypeF32 fileType = iota
fileTypeF16
fileTypeQ4_0
fileTypeQ4_1
fileTypeQ4_1_F16
fileTypeQ4_2 // unused
fileTypeQ4_3 // unused
fileTypeQ8_0
fileTypeQ5_0
fileTypeQ5_1
fileTypeQ2_K
fileTypeQ3_K_S
fileTypeQ3_K_M
fileTypeQ3_K_L
fileTypeQ4_K_S
fileTypeQ4_K_M
fileTypeQ5_K_S
fileTypeQ5_K_M
fileTypeQ6_K
fileTypeIQ2_XXS
fileTypeIQ2_XS
fileTypeQ2_K_S
fileTypeQ3_K_XS
fileTypeIQ3_XXS
2024-04-23 22:18:45 +00:00
fileTypeUnknown
)
2024-04-23 22:18:45 +00:00
func ParseFileType(s string) (fileType, error) {
switch s {
case "F32":
2024-04-23 22:18:45 +00:00
return fileTypeF32, nil
case "F16":
2024-04-23 22:18:45 +00:00
return fileTypeF16, nil
case "Q4_0":
2024-04-23 22:18:45 +00:00
return fileTypeQ4_0, nil
case "Q4_1":
2024-04-23 22:18:45 +00:00
return fileTypeQ4_1, nil
case "Q4_1_F16":
2024-04-23 22:18:45 +00:00
return fileTypeQ4_1_F16, nil
case "Q8_0":
2024-04-23 22:18:45 +00:00
return fileTypeQ8_0, nil
case "Q5_0":
2024-04-23 22:18:45 +00:00
return fileTypeQ5_0, nil
case "Q5_1":
2024-04-23 22:18:45 +00:00
return fileTypeQ5_1, nil
case "Q2_K":
2024-04-23 22:18:45 +00:00
return fileTypeQ2_K, nil
case "Q3_K_S":
2024-04-23 22:18:45 +00:00
return fileTypeQ3_K_S, nil
case "Q3_K_M":
2024-04-23 22:18:45 +00:00
return fileTypeQ3_K_M, nil
case "Q3_K_L":
2024-04-23 22:18:45 +00:00
return fileTypeQ3_K_L, nil
case "Q4_K_S":
2024-04-23 22:18:45 +00:00
return fileTypeQ4_K_S, nil
case "Q4_K_M":
2024-04-23 22:18:45 +00:00
return fileTypeQ4_K_M, nil
case "Q5_K_S":
2024-04-23 22:18:45 +00:00
return fileTypeQ5_K_S, nil
case "Q5_K_M":
2024-04-23 22:18:45 +00:00
return fileTypeQ5_K_M, nil
case "Q6_K":
2024-04-23 22:18:45 +00:00
return fileTypeQ6_K, nil
case "IQ2_XXS":
2024-04-23 22:18:45 +00:00
return fileTypeIQ2_XXS, nil
case "IQ2_XS":
2024-04-23 22:18:45 +00:00
return fileTypeIQ2_XS, nil
case "Q2_K_S":
2024-04-23 22:18:45 +00:00
return fileTypeQ2_K_S, nil
case "Q3_K_XS":
2024-04-23 22:18:45 +00:00
return fileTypeQ3_K_XS, nil
case "IQ3_XXS":
2024-04-23 22:18:45 +00:00
return fileTypeIQ3_XXS, nil
default:
2024-04-23 22:18:45 +00:00
return fileTypeUnknown, fmt.Errorf("unknown fileType: %s", s)
}
}
2024-04-23 22:18:45 +00:00
func (t fileType) String() string {
switch t {
2024-04-23 22:18:45 +00:00
case fileTypeF32:
return "F32"
2024-04-23 22:18:45 +00:00
case fileTypeF16:
return "F16"
2024-04-23 22:18:45 +00:00
case fileTypeQ4_0:
return "Q4_0"
2024-04-23 22:18:45 +00:00
case fileTypeQ4_1:
return "Q4_1"
2024-04-23 22:18:45 +00:00
case fileTypeQ4_1_F16:
return "Q4_1_F16"
2024-04-23 22:18:45 +00:00
case fileTypeQ8_0:
return "Q8_0"
2024-04-23 22:18:45 +00:00
case fileTypeQ5_0:
return "Q5_0"
2024-04-23 22:18:45 +00:00
case fileTypeQ5_1:
return "Q5_1"
2024-04-23 22:18:45 +00:00
case fileTypeQ2_K:
return "Q2_K"
2024-04-23 22:18:45 +00:00
case fileTypeQ3_K_S:
return "Q3_K_S"
2024-04-23 22:18:45 +00:00
case fileTypeQ3_K_M:
return "Q3_K_M"
2024-04-23 22:18:45 +00:00
case fileTypeQ3_K_L:
return "Q3_K_L"
2024-04-23 22:18:45 +00:00
case fileTypeQ4_K_S:
return "Q4_K_S"
2024-04-23 22:18:45 +00:00
case fileTypeQ4_K_M:
return "Q4_K_M"
2024-04-23 22:18:45 +00:00
case fileTypeQ5_K_S:
return "Q5_K_S"
2024-04-23 22:18:45 +00:00
case fileTypeQ5_K_M:
return "Q5_K_M"
2024-04-23 22:18:45 +00:00
case fileTypeQ6_K:
return "Q6_K"
2024-04-23 22:18:45 +00:00
case fileTypeIQ2_XXS:
return "IQ2_XXS"
2024-04-23 22:18:45 +00:00
case fileTypeIQ2_XS:
return "IQ2_XS"
2024-04-23 22:18:45 +00:00
case fileTypeQ2_K_S:
return "Q2_K_S"
2024-04-23 22:18:45 +00:00
case fileTypeQ3_K_XS:
return "Q3_K_XS"
2024-04-23 22:18:45 +00:00
case fileTypeIQ3_XXS:
return "IQ3_XXS"
default:
return "unknown"
}
}
2024-04-23 22:18:45 +00:00
func (t fileType) Value() uint32 {
return uint32(t)
}