| 
									
										
										
										
											2023-07-22 04:33:56 +08:00
										 |  |  | package llm | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-15 01:24:13 +08:00
										 |  |  | // #cgo CFLAGS: -Illama.cpp
 | 
					
						
							|  |  |  | // #cgo darwin,arm64 LDFLAGS: ${SRCDIR}/build/darwin/arm64_static/libllama.a -lstdc++
 | 
					
						
							|  |  |  | // #cgo darwin,amd64 LDFLAGS: ${SRCDIR}/build/darwin/x86_64_static/libllama.a -lstdc++
 | 
					
						
							|  |  |  | // #cgo windows,amd64 LDFLAGS: ${SRCDIR}/build/windows/amd64_static/libllama.a -static -lstdc++
 | 
					
						
							| 
									
										
										
										
											2024-04-27 12:24:53 +08:00
										 |  |  | // #cgo windows,arm64 LDFLAGS: ${SRCDIR}/build/windows/arm64_static/libllama.a -static -lstdc++
 | 
					
						
							| 
									
										
										
										
											2024-03-15 01:24:13 +08:00
										 |  |  | // #cgo linux,amd64 LDFLAGS: ${SRCDIR}/build/linux/x86_64_static/libllama.a -lstdc++
 | 
					
						
							|  |  |  | // #cgo linux,arm64 LDFLAGS: ${SRCDIR}/build/linux/arm64_static/libllama.a -lstdc++
 | 
					
						
							| 
									
										
										
										
											2024-04-05 23:49:04 +08:00
										 |  |  | // #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-15 01:24:13 +08:00
										 |  |  | // #include "llama.h"
 | 
					
						
							|  |  |  | import "C" | 
					
						
							| 
									
										
										
										
											2024-04-05 23:49:04 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"unsafe" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-03-15 01:24:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // SystemInfo is an unused example of calling llama.cpp functions using CGo
 | 
					
						
							|  |  |  | func SystemInfo() string { | 
					
						
							|  |  |  | 	return C.GoString(C.llama_print_system_info()) | 
					
						
							| 
									
										
										
										
											2023-12-21 02:36:01 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-05 23:49:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 06:18:45 +08:00
										 |  |  | func Quantize(infile, outfile string, ftype fileType) error { | 
					
						
							| 
									
										
										
										
											2024-04-05 23:49:04 +08:00
										 |  |  | 	cinfile := C.CString(infile) | 
					
						
							|  |  |  | 	defer C.free(unsafe.Pointer(cinfile)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	coutfile := C.CString(outfile) | 
					
						
							|  |  |  | 	defer C.free(unsafe.Pointer(coutfile)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	params := C.llama_model_quantize_default_params() | 
					
						
							|  |  |  | 	params.nthread = -1 | 
					
						
							| 
									
										
										
										
											2024-04-13 04:55:12 +08:00
										 |  |  | 	params.ftype = ftype.Value() | 
					
						
							| 
									
										
										
										
											2024-04-05 23:49:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-13 04:55:12 +08:00
										 |  |  | 	if rc := C.llama_model_quantize(cinfile, coutfile, ¶ms); rc != 0 { | 
					
						
							|  |  |  | 		return fmt.Errorf("llama_model_quantize: %d", rc) | 
					
						
							| 
									
										
										
										
											2024-04-05 23:49:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |