turboderp / exllamav2

A fast inference library for running LLMs locally on modern consumer-class GPUs
MIT License
3.28k stars 244 forks source link

Fixed multi file and wildcard args #218

Closed SinanAkkoyun closed 6 months ago

SinanAkkoyun commented 7 months ago

Before it couldn't handle wildcard args for me

bartowski1182 commented 6 months ago

@SinanAkkoyun can you provide an example of inputting wildcards? This change seems to have broken wildcard input for me

bartowski1182 commented 6 months ago

Reverting this commit fixes wildcard input for me:

python3 utils/convert_safetensors.py /models/model_name/pytorch*.bin

turboderp commented 6 months ago

Interesting. What shell are you using?

bartowski1182 commented 6 months ago

Just Linux bash

bartowski1182 commented 5 months ago

@SinanAkkoyun any info on how you're using this? I'm still reverting this merge for my use case because I can't convert with wildcards anymore.

bartowski1182 commented 5 months ago

@turboderp do you mind reverting this commit? If this was fixing a real issue I can look at a better fix but for now it's frustrating that it broke wildcard support

SinanAkkoyun commented 5 months ago

@bartowski1182 That's odd, for me it works with simply specifying: python3 utils/convert_safetensors.py /models/model_name/pytorch* (I can not try it out now, I do not have access to my machine atm)

It seems as if the PR only breaks for your environment, if that's the case you could simply copy the old util script into another directory and run it there to convert

bartowski1182 commented 5 months ago

@SinanAkkoyun is that how you would use it? I can't imagine how it would work with a wildcard from the code, since you just run for file in args.input_files:, that doesn't seem to handle using a wildcard at all but would work with a list of files

SinanAkkoyun commented 5 months ago

Idk how but my PR worked for me, perhaps my shell handled that

SinanAkkoyun commented 5 months ago

Just set a simplified version up on the go, tested the input file arg parsing, works fine for fish and bash (ubuntu 20.04)

with at the end, with .bin at the end, all work flawlessly

turboderp commented 5 months ago

It also works for me (bash). Previously you'd have to run it like python convert_safetensors.py "*.bin" since otherwise *.bin would be expanded by the shell to a list of files matching the pattern. Adding nargs='+' correctly catches that list and so wildcard matching can be done by the shell.

What happens if you run this?

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("filenames", nargs="+", type=str)
args = parser.parse_args()
print(args.filenames)
bartowski1182 commented 5 months ago

I've isolated the problem a bit

If I run the code directly from my terminal, it works

If I run it inside a docker container, it doesn't..

I'm not sure how running from a docker container is making it not work, it doesn't make any sense to behave differently, but now that I know what I'm looking for I should have an easier time either figuring out what's broken or figuring out how to fix this code so that it works in both scenarios

bartowski1182 commented 5 months ago

Made a fix for it, seems that docker commands won't expand wildcard files like regular bash does, will now work for both:

https://github.com/turboderp/exllamav2/pull/344