2024-04-12 20:55:12 +00:00
|
|
|
package llm
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2024-04-23 22:18:45 +00:00
|
|
|
type fileType uint32
|
2024-04-12 20:55:12 +00:00
|
|
|
|
|
|
|
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
|
2024-05-23 20:21:49 +00:00
|
|
|
fileTypeIQ3_XS
|
2024-04-23 22:18:45 +00:00
|
|
|
fileTypeIQ3_XXS
|
2024-05-23 20:21:49 +00:00
|
|
|
fileTypeIQ1_S
|
|
|
|
fileTypeIQ4_NL
|
|
|
|
fileTypeIQ3_S
|
2024-11-24 18:33:33 +00:00
|
|
|
fileTypeIQ3_M
|
2024-05-23 20:21:49 +00:00
|
|
|
fileTypeIQ2_S
|
|
|
|
fileTypeIQ2_M
|
2024-11-24 18:33:33 +00:00
|
|
|
fileTypeIQ4_XS
|
2024-05-23 20:21:49 +00:00
|
|
|
fileTypeIQ1_M
|
|
|
|
fileTypeBF16
|
2024-04-12 20:55:12 +00:00
|
|
|
|
2024-04-23 22:18:45 +00:00
|
|
|
fileTypeUnknown
|
2024-04-12 20:55:12 +00:00
|
|
|
)
|
|
|
|
|
2024-04-23 22:18:45 +00:00
|
|
|
func ParseFileType(s string) (fileType, error) {
|
2024-04-12 20:55:12 +00:00
|
|
|
switch s {
|
|
|
|
case "F32":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeF32, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "F16":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeF16, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q4_0":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ4_0, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q4_1":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ4_1, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q4_1_F16":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ4_1_F16, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q8_0":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ8_0, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q5_0":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ5_0, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q5_1":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ5_1, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q2_K":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ2_K, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q3_K_S":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ3_K_S, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q3_K_M":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ3_K_M, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q3_K_L":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ3_K_L, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q4_K_S":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ4_K_S, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q4_K_M":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ4_K_M, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q5_K_S":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ5_K_S, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q5_K_M":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ5_K_M, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q6_K":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ6_K, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "IQ2_XXS":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeIQ2_XXS, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "IQ2_XS":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeIQ2_XS, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "Q2_K_S":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeQ2_K_S, nil
|
2024-05-23 20:21:49 +00:00
|
|
|
case "IQ3_XS":
|
|
|
|
return fileTypeIQ3_XS, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
case "IQ3_XXS":
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeIQ3_XXS, nil
|
2024-05-23 20:21:49 +00:00
|
|
|
case "IQ1_S":
|
|
|
|
return fileTypeIQ1_S, nil
|
|
|
|
case "IQ4_NL":
|
|
|
|
return fileTypeIQ4_NL, nil
|
|
|
|
case "IQ3_S":
|
|
|
|
return fileTypeIQ3_S, nil
|
2024-11-24 18:33:33 +00:00
|
|
|
case "IQ3_M":
|
|
|
|
return fileTypeIQ3_M, nil
|
2024-05-23 20:21:49 +00:00
|
|
|
case "IQ2_S":
|
|
|
|
return fileTypeIQ2_S, nil
|
|
|
|
case "IQ4_XS":
|
|
|
|
return fileTypeIQ4_XS, nil
|
|
|
|
case "IQ2_M":
|
|
|
|
return fileTypeIQ2_M, nil
|
|
|
|
case "IQ1_M":
|
|
|
|
return fileTypeIQ1_M, nil
|
|
|
|
case "BF16":
|
|
|
|
return fileTypeBF16, nil
|
2024-04-12 20:55:12 +00:00
|
|
|
default:
|
2024-04-23 22:18:45 +00:00
|
|
|
return fileTypeUnknown, fmt.Errorf("unknown fileType: %s", s)
|
2024-04-12 20:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:18:45 +00:00
|
|
|
func (t fileType) String() string {
|
2024-04-12 20:55:12 +00:00
|
|
|
switch t {
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeF32:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "F32"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeF16:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "F16"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ4_0:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q4_0"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ4_1:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q4_1"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ4_1_F16:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q4_1_F16"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ8_0:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q8_0"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ5_0:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q5_0"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ5_1:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q5_1"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ2_K:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q2_K"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ3_K_S:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q3_K_S"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ3_K_M:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q3_K_M"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ3_K_L:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q3_K_L"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ4_K_S:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q4_K_S"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ4_K_M:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q4_K_M"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ5_K_S:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q5_K_S"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ5_K_M:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q5_K_M"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ6_K:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q6_K"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeIQ2_XXS:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "IQ2_XXS"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeIQ2_XS:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "IQ2_XS"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeQ2_K_S:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "Q2_K_S"
|
2024-05-23 20:21:49 +00:00
|
|
|
case fileTypeIQ3_XS:
|
|
|
|
return "IQ3_XS"
|
2024-04-23 22:18:45 +00:00
|
|
|
case fileTypeIQ3_XXS:
|
2024-04-12 20:55:12 +00:00
|
|
|
return "IQ3_XXS"
|
2024-05-23 20:21:49 +00:00
|
|
|
case fileTypeIQ1_S:
|
|
|
|
return "IQ1_S"
|
|
|
|
case fileTypeIQ4_NL:
|
|
|
|
return "IQ4_NL"
|
|
|
|
case fileTypeIQ3_S:
|
|
|
|
return "IQ3_S"
|
2024-11-24 18:33:33 +00:00
|
|
|
case fileTypeIQ3_M:
|
|
|
|
return "IQ3_M"
|
2024-05-23 20:21:49 +00:00
|
|
|
case fileTypeIQ2_S:
|
|
|
|
return "IQ2_S"
|
|
|
|
case fileTypeIQ4_XS:
|
|
|
|
return "IQ4_XS"
|
|
|
|
case fileTypeIQ2_M:
|
|
|
|
return "IQ2_M"
|
|
|
|
case fileTypeIQ1_M:
|
|
|
|
return "IQ1_M"
|
|
|
|
case fileTypeBF16:
|
|
|
|
return "BF16"
|
2024-04-12 20:55:12 +00:00
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:18:45 +00:00
|
|
|
func (t fileType) Value() uint32 {
|
2024-04-12 20:55:12 +00:00
|
|
|
return uint32(t)
|
|
|
|
}
|