Skip to content

Commit

Permalink
New program-level -q flag, that must be placed before the command wor…
Browse files Browse the repository at this point in the history
…d. Currently used by 'header', 'listkeys', and 'metadata' commands
  • Loading branch information
by321 committed Sep 19, 2023
1 parent 3da98d2 commit aa6a159
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

This is a light-weight utility program for [safetensors files](https://github.com/huggingface/safetensors "safetensors files") written in Python only (no major external dependencies). Currently it can do the following:


Usage: safetensors_util.py [OPTIONS] COMMAND [ARGS]...

Options:
--version Show the version and exit.
--help Show this message and exit.

--version Show the version and exit.
-q, --quiet quiet mode, don't print informational stuff
--help Show this message and exit.

Commands:
checklora see if input file is a SD 1.x LoRA file
extracthdr extract file header and save to output file
Expand Down
7 changes: 5 additions & 2 deletions safetensors_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
help="overwrite existing files")
fix_ued_flag=click.option("-pm","--parse-more",default=False,is_flag=True, show_default=True,
help="when printing metadata, unescaped doublequotes to make text more readable" )
quiet_flag=click.option("-q","--quiet",default=False,is_flag=True, show_default=True,
help="Quiet mode, don't print informational stuff" )

@click.group()

@click.version_option(version=3)
@quiet_flag

@click.pass_context
def cli(ctx):
def cli(ctx,quiet:bool):
# ensure that ctx.obj exists and is a dict (in case `cli()` is called
# by means other than the `if` block below)
ctx.ensure_object(dict)
ctx.obj['quiet'] = quiet

@cli.command(name="header",short_help="print file header")
@readonly_input_file
Expand Down
6 changes: 3 additions & 3 deletions safetensors_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def WriteMetadataToHeader(cmdLine:dict,in_st_file:str,in_json_file:str,output_fi
return i

def PrintHeader(cmdLine:dict,input_file:str) -> int:
s=SafeTensorsFile.open_file(input_file)
s=SafeTensorsFile.open_file(input_file,cmdLine['quiet'])
js=s.get_header()
if js is None: return -1

Expand Down Expand Up @@ -106,7 +106,7 @@ def _ParseMore(d:dict):
_ParseMore(value)

def PrintMetadata(cmdLine:dict,input_file:str) -> int:
s=SafeTensorsFile.open_file(input_file)
s=SafeTensorsFile.open_file(input_file,cmdLine['quiet'])
js=s.get_header()
if js is None: return -1

Expand All @@ -121,7 +121,7 @@ def PrintMetadata(cmdLine:dict,input_file:str) -> int:
return 0

def HeaderKeysToLists(cmdLine:dict,input_file:str) -> int:
s=SafeTensorsFile.open_file(input_file,quiet=True)
s=SafeTensorsFile.open_file(input_file,cmdLine['quiet'])
js=s.get_header()
if js is None: return -1

Expand Down

0 comments on commit aa6a159

Please sign in to comment.