filetype.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package llm
  2. import "fmt"
  3. type fileType uint32
  4. const (
  5. fileTypeF32 fileType = iota
  6. fileTypeF16
  7. fileTypeQ4_0
  8. fileTypeQ4_1
  9. fileTypeQ4_1_F16
  10. fileTypeQ4_2 // unused
  11. fileTypeQ4_3 // unused
  12. fileTypeQ8_0
  13. fileTypeQ5_0
  14. fileTypeQ5_1
  15. fileTypeQ2_K
  16. fileTypeQ3_K_S
  17. fileTypeQ3_K_M
  18. fileTypeQ3_K_L
  19. fileTypeQ4_K_S
  20. fileTypeQ4_K_M
  21. fileTypeQ5_K_S
  22. fileTypeQ5_K_M
  23. fileTypeQ6_K
  24. fileTypeIQ2_XXS
  25. fileTypeIQ2_XS
  26. fileTypeQ2_K_S
  27. fileTypeIQ3_XS
  28. fileTypeIQ3_XXS
  29. fileTypeIQ1_S
  30. fileTypeIQ4_NL
  31. fileTypeIQ3_S
  32. fileTypeIQ2_S
  33. fileTypeIQ4_XS
  34. fileTypeIQ2_M
  35. fileTypeIQ1_M
  36. fileTypeBF16
  37. fileTypeUnknown
  38. )
  39. func ParseFileType(s string) (fileType, error) {
  40. switch s {
  41. case "F32":
  42. return fileTypeF32, nil
  43. case "F16":
  44. return fileTypeF16, nil
  45. case "Q4_0":
  46. return fileTypeQ4_0, nil
  47. case "Q4_1":
  48. return fileTypeQ4_1, nil
  49. case "Q4_1_F16":
  50. return fileTypeQ4_1_F16, nil
  51. case "Q8_0":
  52. return fileTypeQ8_0, nil
  53. case "Q5_0":
  54. return fileTypeQ5_0, nil
  55. case "Q5_1":
  56. return fileTypeQ5_1, nil
  57. case "Q2_K":
  58. return fileTypeQ2_K, nil
  59. case "Q3_K_S":
  60. return fileTypeQ3_K_S, nil
  61. case "Q3_K_M":
  62. return fileTypeQ3_K_M, nil
  63. case "Q3_K_L":
  64. return fileTypeQ3_K_L, nil
  65. case "Q4_K_S":
  66. return fileTypeQ4_K_S, nil
  67. case "Q4_K_M":
  68. return fileTypeQ4_K_M, nil
  69. case "Q5_K_S":
  70. return fileTypeQ5_K_S, nil
  71. case "Q5_K_M":
  72. return fileTypeQ5_K_M, nil
  73. case "Q6_K":
  74. return fileTypeQ6_K, nil
  75. case "IQ2_XXS":
  76. return fileTypeIQ2_XXS, nil
  77. case "IQ2_XS":
  78. return fileTypeIQ2_XS, nil
  79. case "Q2_K_S":
  80. return fileTypeQ2_K_S, nil
  81. case "IQ3_XS":
  82. return fileTypeIQ3_XS, nil
  83. case "IQ3_XXS":
  84. return fileTypeIQ3_XXS, nil
  85. case "IQ1_S":
  86. return fileTypeIQ1_S, nil
  87. case "IQ4_NL":
  88. return fileTypeIQ4_NL, nil
  89. case "IQ3_S":
  90. return fileTypeIQ3_S, nil
  91. case "IQ2_S":
  92. return fileTypeIQ2_S, nil
  93. case "IQ4_XS":
  94. return fileTypeIQ4_XS, nil
  95. case "IQ2_M":
  96. return fileTypeIQ2_M, nil
  97. case "IQ1_M":
  98. return fileTypeIQ1_M, nil
  99. case "BF16":
  100. return fileTypeBF16, nil
  101. default:
  102. return fileTypeUnknown, fmt.Errorf("unknown fileType: %s", s)
  103. }
  104. }
  105. func (t fileType) String() string {
  106. switch t {
  107. case fileTypeF32:
  108. return "F32"
  109. case fileTypeF16:
  110. return "F16"
  111. case fileTypeQ4_0:
  112. return "Q4_0"
  113. case fileTypeQ4_1:
  114. return "Q4_1"
  115. case fileTypeQ4_1_F16:
  116. return "Q4_1_F16"
  117. case fileTypeQ8_0:
  118. return "Q8_0"
  119. case fileTypeQ5_0:
  120. return "Q5_0"
  121. case fileTypeQ5_1:
  122. return "Q5_1"
  123. case fileTypeQ2_K:
  124. return "Q2_K"
  125. case fileTypeQ3_K_S:
  126. return "Q3_K_S"
  127. case fileTypeQ3_K_M:
  128. return "Q3_K_M"
  129. case fileTypeQ3_K_L:
  130. return "Q3_K_L"
  131. case fileTypeQ4_K_S:
  132. return "Q4_K_S"
  133. case fileTypeQ4_K_M:
  134. return "Q4_K_M"
  135. case fileTypeQ5_K_S:
  136. return "Q5_K_S"
  137. case fileTypeQ5_K_M:
  138. return "Q5_K_M"
  139. case fileTypeQ6_K:
  140. return "Q6_K"
  141. case fileTypeIQ2_XXS:
  142. return "IQ2_XXS"
  143. case fileTypeIQ2_XS:
  144. return "IQ2_XS"
  145. case fileTypeQ2_K_S:
  146. return "Q2_K_S"
  147. case fileTypeIQ3_XS:
  148. return "IQ3_XS"
  149. case fileTypeIQ3_XXS:
  150. return "IQ3_XXS"
  151. case fileTypeIQ1_S:
  152. return "IQ1_S"
  153. case fileTypeIQ4_NL:
  154. return "IQ4_NL"
  155. case fileTypeIQ3_S:
  156. return "IQ3_S"
  157. case fileTypeIQ2_S:
  158. return "IQ2_S"
  159. case fileTypeIQ4_XS:
  160. return "IQ4_XS"
  161. case fileTypeIQ2_M:
  162. return "IQ2_M"
  163. case fileTypeIQ1_M:
  164. return "IQ1_M"
  165. case fileTypeBF16:
  166. return "BF16"
  167. default:
  168. return "unknown"
  169. }
  170. }
  171. func (t fileType) Value() uint32 {
  172. return uint32(t)
  173. }