-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quantize command to cli and use aligned offheap memory
- Loading branch information
Showing
18 changed files
with
513 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
jlama-cli/src/main/java/com/github/tjake/jlama/cli/commands/QuantizeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.github.tjake.jlama.cli.commands; | ||
|
||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import com.github.tjake.jlama.safetensors.DType; | ||
import com.github.tjake.jlama.safetensors.SafeTensorSupport; | ||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "quantize", description = "Quantize the specified model") | ||
|
||
public class QuantizeCommand extends BaseCommand { | ||
|
||
@CommandLine.Parameters(index = "1", arity = "0..1", description = "The output location") | ||
protected Path output; | ||
|
||
@CommandLine.Option(names = { "-q", "--quantization"}, description = "Model quantization type", arity = "1") | ||
protected DType modelQuantization; | ||
|
||
@CommandLine.Option(names = {"-s", "--skip-layer"}, description = "Layer name prefix to not quantize") | ||
protected String[] skipLayerPrefixes; | ||
|
||
@Override | ||
public void run() { | ||
|
||
if (!model.exists()) { | ||
System.err.println("Model location does not exist: " + model); | ||
System.exit(1); | ||
} | ||
|
||
File baseDir = model.isFile() ? model.getParentFile() : model; | ||
|
||
if (!baseDir.isDirectory()) { | ||
System.err.println("Model directory does not exist: " + baseDir); | ||
System.exit(1); | ||
} | ||
|
||
try { | ||
Path out = SafeTensorSupport.quantizeModel(baseDir.toPath(), modelQuantization, skipLayerPrefixes, Optional.ofNullable(output)); | ||
|
||
System.out.println("Quantized model written to: " + out); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
System.exit(2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
jlama-core/src/main/java/com/github/tjake/jlama/safetensors/WeightLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.