this post was submitted on 28 Apr 2025
39 points (97.6% liked)
LocalLLaMA
2929 readers
37 users here now
Welcome to LocalLLaMA! Here we discuss running and developing machine learning models at home. Lets explore cutting edge open source neural network technology together.
Get support from the community! Ask questions, share prompts, discuss benchmarks, get hyped at the latest and greatest model releases! Enjoy talking about our awesome hobby.
As ambassadors of the self-hosting machine learning community, we strive to support each other and share our enthusiasm in a positive constructive way.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
QwQ-32B-Q6_K:
Amt:3313, Process:107.21s (1.74T/s), Generate:3463.16s (0.96T/s), Total:3570.37s
QwQ-32B-Q6_K - Thoughts (11010 characters)
Okay, let's tackle this problem step by step. The user wants a script that sorts all .gguf files into subdirectories based on their publisher, which is derived from the URLs in the dl*.txt files. Hmm, first, I need to figure out how to extract the publisher from each URL.
The example URL given is
https://huggingface.co/unsloth/Qwen3-30B-A3B-GGUF/resolve/main/Qwen3-30B-A3B-Q6_K.gguf?download=true
, and the publisher here is 'unsloth'. Looking at the URL structure, the publisher is the first path component after the domain. So, after 'huggingface.co', the next part is the publisher.So, the plan is: for each .gguf file in the current directory, find its corresponding URL in any of the dl*.txt files. Then parse that URL to get the publisher, create a directory if it doesn't exist, and move the file there. But wait, how do I link each .gguf file to its URL? The filenames might not directly correspond to the URLs, so maybe the filenames are part of the URL paths?
Alternatively, perhaps each line in the dl*.txt files contains a URL that ends with the filename. So, the filename is the last part of the URL before any query parameters. For example, in the example URL, the filename is Qwen3-30B-A3B-Q6_K.gguf. So, the script can look through all the dl*.txt files, parse each URL, extract the filename from the URL, and then check if that filename exists in the current directory. If it does, then we can get the publisher from that URL and move the file accordingly.
Wait, but the problem states that the URLs are in the dl files, and each .gguf file was downloaded from one of those URLs. So each .gguf file corresponds to exactly one URL in one of the dl files. Therefore, the script needs to:
But first, how to parse the URLs correctly. Let's think about splitting the URL. The example URL's path after the domain is '/unsloth/Qwen3-30B-A3B-GGUF/resolve/main/Qwen3-30B-A3B-Q6_K.gguf'. The first path component after the domain is 'unsloth', which is the publisher. So splitting the path by '/' and taking the second element (since the first is empty due to leading '/') would give the publisher.
For the filename, the last part of the path before any query parameters. So split the URL on '?' to get the path part, then split on '/' and take the last element.
Potential edge cases: URLs with different domains? The example uses huggingface.co, but maybe others could be present. But the problem says "the publisher can only be found in the URL used to originally download each .gguf file", so the structure should be consistent. So the first path component after the domain is always the publisher.
Now, steps for the script:
First, process all dl*.txt files. For each file:
How to do this in bash? Maybe using parameter expansion or cut.
Alternatively, using awk or sed. Let's think of code snippets.
Parsing the publisher:
Given a URL like 'https://huggingface.co/unsloth/...', the path starts after 'huggingface.co/'. So splitting the URL into parts after the domain.
Maybe using cut:
domain_part=$(echo $url | cut -d '/' -f 3) # gets huggingface.co path_part=$(echo $url | cut -d '/' -f 4-) # gets everything after the domain
Then the first element of path_part is the publisher. So split path_part on '/' again.
publisher=$(echo $path_part | cut -d '/' -f 1)
Wait, let's see:
For the example URL:
Original URL: https://huggingface.co/unsloth/Qwen3-30B-A3B-GGUF/resolve/main/Qwen3-30B-A3B-Q6_K.gguf?download=true
Breaking down:
After splitting by '/', the components are:
0: https: 1: 2: huggingface.co 3: unsloth 4: Qwen3-30B-A3B-GGUF 5: resolve 6: main 7: Qwen3-30B-A3B-Q6_K.gguf?download=true
Wait, actually, the URL is split into parts by the slashes. The third component (index 2 if starting from 0) is huggingface.co. The fourth component (index 3) is unsloth, which is the publisher.
So, to get the publisher, we can take the 4th field when splitting by '/'.
Wait, perhaps using:
publisher=$(echo $url | awk -F/ '{print $4}')
Yes, because:
The URL is split into fields by '/', so $4 would be 'unsloth'.
Similarly, for the filename:
The filename is the last part before any '?', take the first part, then split on '/' and take the last element. Alternatively, using basename:
filename=$(basename $(echo $url | cut -d '?' -f1))
Yes, that's better. For example, the URL part before ? is:
https://huggingface.co/unsloth/Qwen3-30B-A3B-GGUF/resolve/main/Qwen3-30B-A3B-Q6_K.gguf
basename of that is "Qwen3-30B-A3B-Q6_K.gguf".
So putting it all together, for each URL line:
publisher=$(echo "$url" | awk -F/ '{print $4}') filename=$(basename "$(echo "$url" | cut -d '?' -f1)")
Then, we can build an associative array (in bash) mapping filenames to publishers.
Once all URLs are processed, we can loop over the .gguf files in the current directory. For each file:
Now, in bash, associative arrays can be used. Let's structure the code:
First, read all the dl files.
declare -A publisher_map
for dlfile in dl*.txt; do while IFS= read -r line; do # Ignore comments and empty lines if [[ $line == #* || -z $line ]]; then continue fi url="$line"
done
Then, process each .gguf file:
for file in *.gguf; do if [[ ! -f $file ]]; then continue fi fname=$(basename "$file")
done
Wait, but in bash, checking if a key exists in an associative array uses -v, so that part is okay.
But need to make sure that the filenames are exactly as they appear in the URL's path. For example, if the URL's filename has a different case, or maybe trailing spaces? Probably need to ensure exact matches.
Another thing: what about files that are not in any of the dl files? The problem says "all .gguf files", but perhaps some files were not downloaded via these URLs? The user might want those to be skipped, or maybe an error. But according to the problem statement, they need to be sorted into subdirectories based on their original download URLs, so files not present in any dl file ca [...trimmed because lemmy won't handle so many chars]
QwQ-32B-Q6_K - Answer
Here's a bash script to organize the .gguf files into publisher directories based on their download URLs:To use this script:
sort_gguf.sh
in your current directorychmod +x sort_gguf.sh
./sort_gguf.sh
This script does the following:
Note: The script assumes: