-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmonitor_and_split.sh
More file actions
executable file
·110 lines (98 loc) · 5.69 KB
/
monitor_and_split.sh
File metadata and controls
executable file
·110 lines (98 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
#***************************************************************#
#** This script is part of Thireus' GGUF Tool Suite. **#
#** monitor_and_split.sh is a script that auto splits GGUF **#
#** models. **#
#** **#
#** ********************************************************* **#
#** --------------- Updated: Dec-27-2025 -------------------- **#
#** ********************************************************* **#
#** **#
#** Author: Thireus <gguf@thireus.com> **#
#** **#
#** https://gguf.thireus.com/ **#
#** Thireus' GGUF Tool Suite - Quantize LLMs Like a Chef **#
#** · · ·~° **#
#** Λ,,Λ ₚₚₗ ·° ᵍᵍᵐˡ · ɪᴋ_ʟʟᴀᴍᴀ.ᴄᴘᴘ° ᴮᶠ¹⁶ · **#
#** (:·ω·) 。··° · ɢɢᴜғ ·°· ₕᵤ𝓰𝓰ᵢₙ𝓰𝒻ₐ𝒸ₑ ·° **#
#** / o―ヽニニフ)) · · ɪǫ3_xxs ~·° **#
#** し―-J **#
#** **#
#** Copyright © 2025 - Thireus. Wᵣₒₜ 𝒹ᵢₛ ᵢₙ ₁₋ᵦᵢₜ ₘₒₒ𝒹 **#
#***************************************************************#
#**PLEASE REFER TO THE README FILE FOR ADDITIONAL INFORMATION!**#
#***************************************************************#
# Exit on error, undefined variable, or pipe failure
set -euo pipefail
# GLOBAL OPTION: delete original .gguf after successful split?
# Default is "false". Override by exporting DELETE_ORIGINAL=true or editing here.
DELETE_ORIGINAL="${DELETE_ORIGINAL:-false}"
# Trap SIGINT/SIGTERM to allow a clean exit message
trap 'echo "[$(date "+%Y-%m-%d %H:%M:%S")] Received termination signal. Exiting." >&2; exit 0' SIGINT SIGTERM
# Directory to monitor: first argument, default to current directory if not provided
WATCH_DIR="${1:-.}"
# Verify that the directory exists and is indeed a directory
if [[ ! -d "$WATCH_DIR" ]]; then
echo "Error: '$WATCH_DIR' is not a directory or does not exist."
exit 1
fi
# Check that llama-gguf-split is available
if ! command -v llama-gguf-split &>/dev/null; then
echo "Warning: 'llama-gguf-split' not found in PATH. Ensure it is installed and in PATH."
# We do not exit here; we'll let the split fail per-file if it's missing.
fi
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting monitoring of directory: $WATCH_DIR"
echo "Polling every 60 seconds. Looking for '*-SPECIAL.gguf' older than 10 minutes."
# Infinite loop
while true; do
# Find files matching "*-SPECIAL.gguf" in WATCH_DIR (non-recursive by default; adjust -maxdepth as needed)
# whose modification time is more than 10 minutes ago.
# Using -maxdepth 1 to limit to the top-level of WATCH_DIR. If you want recursive search, remove -maxdepth 1.
while IFS= read -r -d '' file; do
# Get the base filename (no directory)
filename="$(basename "$file")"
# Strip the .gguf extension
base="${filename%.gguf}"
# Define the split directory name
split_dir="$WATCH_DIR/${base}_SPLIT"
# If the split directory does not exist, create it and run the split
if [[ ! -d "$split_dir" ]]; then
timestamp="$(date '+%Y-%m-%d %H:%M:%S')"
echo "[$timestamp] Detected file older than 10 minutes: '$file'"
echo "[$timestamp] Creating directory: '$split_dir'"
if mkdir -p "$split_dir"; then
echo "[$timestamp] Directory created successfully."
else
echo "[$timestamp] ERROR: Failed to create directory '$split_dir'. Skipping this file."
continue
fi
# Build the output split filename
out_gguf="$split_dir/${base}_TENSOR"
echo "[$timestamp] Running split: llama-gguf-split --no-tensor-first-split --split-max-tensors 1 '$file' '$out_gguf'"
if llama-gguf-split --no-tensor-first-split --split-max-tensors 1 "$file" "$out_gguf"; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Split succeeded for '$file'. Output in '$split_dir/'."
# If enabled, delete the original gguf
if [[ "$DELETE_ORIGINAL" == "true" ]]; then
if rm -f "$file"; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Deleted original file: '$file'."
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARNING: Failed to delete original file: '$file'."
fi
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Skipping deletion of original (DELETE_ORIGINAL=false)."
fi
chmod 444 "$split_dir"/*.gguf # Lock files
else
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: Split failed for '$file'. You may want to check llama-gguf-split availability or file integrity."
# Optionally, could remove the created directory or leave for inspection.
fi
else
# Directory already exists: skip
:
# If you want verbose logging, uncomment the next line:
# echo "[$(date '+%Y-%m-%d %H:%M:%S')] Split directory already exists for '$file'; skipping."
fi
done < <(find "$WATCH_DIR" -maxdepth 1 \( -type f -o -type l \) -name "*-SPECIAL.gguf" -mmin +10 -print0)
# Sleep for 60 seconds before next check
sleep 60
done