-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prabhu Subramanian <[email protected]>
- Loading branch information
Showing
8 changed files
with
228 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dataset/ | ||
adapters/ | ||
out.txt | ||
unsloth/ | ||
CycloneDX/ |
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,12 @@ | ||
FROM ./cdx1-bf16.gguf | ||
|
||
PARAMETER num_ctx 16384 | ||
PARAMETER temperature 0.05 | ||
PARAMETER top_k 10 | ||
PARAMETER top_p 0.5 | ||
|
||
SYSTEM """You are cdxgen, a CycloneDX and an xBOM expert.""" | ||
|
||
LICENSE """ | ||
apache-2.0 | ||
""" |
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
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,60 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
TUNING_TOOL=mlx | ||
BASE_MODEL=unsloth/phi-4 | ||
BASE_MODEL_MLX=${BASE_MODEL}-${TUNING_TOOL} | ||
HF_ORG=CycloneDX | ||
TOOL_BASE_MODEL=cdx1 | ||
NUM_LAYERS=16 | ||
|
||
FUSED_MODEL=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL} | ||
FUSED_GGUF_MODEL=${HF_ORG}/${TOOL_BASE_MODEL}-gguf | ||
QUANT_MODEL_8BIT=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL}-8bit | ||
QUANT_MODEL_6BIT=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL}-6bit | ||
QUANT_MODEL_4BIT=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL}-4bit | ||
|
||
### mlx-lm needs train.jsonl and valid.jsonl | ||
rm -rf dataset ${HF_ORG} adapters ${BASE_MODEL} | ||
mkdir -p dataset ${HF_ORG} | ||
|
||
node prepare.js dataset | ||
node validator.js dataset | ||
|
||
echo "Test base model with the prompt 'Tell me about cdxgen'. Usually yields a low-quality response." | ||
mlx_lm.generate --model ${BASE_MODEL} --prompt "Tell me about cdxgen" --temp 0.05 | ||
|
||
# We first convert from HF to mlx | ||
rm -rf ${BASE_MODEL_MLX} | ||
mlx_lm.convert --hf-path ${BASE_MODEL} --mlx-path ${BASE_MODEL_MLX} | ||
|
||
echo "Weight-Decomposed Low-Rank Adaptation (DoRA) fine-tuning ${BASE_MODEL_MLX} with cdx1 dataset. This might take a while ..." | ||
mlx_lm.lora --model ${BASE_MODEL_MLX} --train --data dataset --fine-tune-type dora --batch-size 1 --num-layers ${NUM_LAYERS} --iters 1000 --grad-checkpoint | ||
|
||
echo "Fuse model to ${FUSED_MODEL} using the cdx1 adapters" | ||
rm -rf ${FUSED_MODEL} ${FUSED_GGUF_MODEL} | ||
mlx_lm.fuse --model ${BASE_MODEL_MLX} --adapter-path adapters --hf-path ${FUSED_MODEL} --save-path ${FUSED_MODEL} --export-gguf --gguf-path cdx1-bf16.gguf | ||
|
||
echo "Test fused model with the prompt 'Tell me about cdxgen'. Must yield a better response." | ||
mlx_lm.generate --model ${FUSED_MODEL} --prompt "Tell me about cdxgen" --temp 0.05 | ||
|
||
mkdir -p ${FUSED_GGUF_MODEL} | ||
mv ${FUSED_MODEL}/cdx1-bf16.gguf ${FUSED_GGUF_MODEL} | ||
cp Modelfile ${FUSED_GGUF_MODEL}/ | ||
|
||
echo "Create quantized models" | ||
rm -rf ${QUANT_MODEL_8BIT} | ||
mlx_lm.convert --hf-path ${FUSED_MODEL} --mlx-path ${QUANT_MODEL_8BIT} -q --q-bits 8 --dtype bfloat16 | ||
echo "Test ${QUANT_MODEL_8BIT} with the prompt 'Tell me about cdxgen'. Must yield a better response." | ||
mlx_lm.generate --model ${QUANT_MODEL_8BIT} --prompt "Tell me about cdxgen" --temp 0.05 | ||
|
||
rm -rf ${QUANT_MODEL_6BIT} | ||
mlx_lm.convert --hf-path ${FUSED_MODEL} --mlx-path ${QUANT_MODEL_6BIT} -q --q-bits 6 --dtype bfloat16 | ||
echo "Test ${QUANT_MODEL_6BIT} with the prompt 'Tell me about cdxgen'. Must yield a better response." | ||
mlx_lm.generate --model ${QUANT_MODEL_6BIT} --prompt "Tell me about cdxgen" --temp 0.05 | ||
|
||
rm -rf ${QUANT_MODEL_4BIT} | ||
mlx_lm.convert --hf-path ${FUSED_MODEL} --mlx-path ${QUANT_MODEL_4BIT} -q --q-bits 4 --dtype bfloat16 | ||
echo "Test ${QUANT_MODEL_4BIT} with the prompt 'Tell me about cdxgen'. Must yield a better response." | ||
mlx_lm.generate --model ${QUANT_MODEL_4BIT} --prompt "Tell me about cdxgen" --temp 0.05 | ||
|
||
rm -rf dataset adapters ${BASE_MODEL} |
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,34 @@ | ||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
import process from "node:process"; | ||
|
||
import { dirNameStr, getAllFiles } from "../../lib/helpers/utils.js"; | ||
const jsonlFiles = getAllFiles(dirNameStr, "**/*.jsonl", { | ||
exclude: ["**/{train, valid}.jsonl"], | ||
}); | ||
let datasetDir = "dataset"; | ||
const argv = process.argv.slice(2); | ||
if (argv.length > 1) { | ||
datasetDir = argv[1]; | ||
} | ||
|
||
const TRAIN_FILE = join(datasetDir, "train.jsonl"); | ||
const VALID_FILE = join(datasetDir, "valid.jsonl"); | ||
const trainData = []; | ||
const validData = []; | ||
|
||
for (const jf of jsonlFiles) { | ||
const lines = readFileSync(jf, "utf-8"); | ||
trainData.push(lines); | ||
if (jf.includes("readme") || jf.includes("cdxgen") || jf.includes("cli")) { | ||
validData.push(lines); | ||
} | ||
} | ||
|
||
mkdirSync(datasetDir, { recursive: true }); | ||
if (trainData.length) { | ||
writeFileSync(TRAIN_FILE, trainData.join("\n")); | ||
} | ||
if (validData.length) { | ||
writeFileSync(VALID_FILE, validData.join("\n")); | ||
} |
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,25 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
export HF_HUB_ENABLE_HF_TRANSFER=0 | ||
HF_ORG=CycloneDX | ||
TUNING_TOOL=mlx | ||
TOOL_BASE_MODEL=cdx1 | ||
FUSED_MODEL=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL} | ||
FUSED_GGUF_MODEL=${HF_ORG}/${TOOL_BASE_MODEL}-gguf | ||
QUANT_MODEL_8BIT=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL}-8bit | ||
QUANT_MODEL_6BIT=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL}-6bit | ||
QUANT_MODEL_4BIT=${HF_ORG}/${TOOL_BASE_MODEL}-${TUNING_TOOL}-4bit | ||
|
||
huggingface-cli whoami | ||
|
||
echo "Uploading datasets" | ||
huggingface-cli upload --repo-type dataset CycloneDX/cdx-docs ./cdxgen-docs cdxgen-docs | ||
huggingface-cli upload --repo-type dataset CycloneDX/cdx-docs ./guides guides | ||
|
||
echo "Uploading models. Please wait ..." | ||
huggingface-cli upload --repo-type model ${QUANT_MODEL_8BIT} ./${QUANT_MODEL_8BIT} . | ||
huggingface-cli upload --repo-type model ${QUANT_MODEL_6BIT} ./${QUANT_MODEL_6BIT} . | ||
huggingface-cli upload --repo-type model ${QUANT_MODEL_4BIT} ./${QUANT_MODEL_4BIT} . | ||
|
||
huggingface-cli upload --repo-type model ${FUSED_MODEL} ./${FUSED_MODEL} . | ||
huggingface-cli upload --repo-type model ${FUSED_GGUF_MODEL} ./${FUSED_GGUF_MODEL} . |
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