mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tidy(mm): remove unused code in select_hf_files.py
This commit is contained in:
parent
02bde7bb75
commit
93dd3c848e
@ -74,24 +74,6 @@ def filter_files(
|
|||||||
return sorted(_filter_by_variant(paths, variant))
|
return sorted(_filter_by_variant(paths, variant))
|
||||||
|
|
||||||
|
|
||||||
def get_variant_label(path: Path) -> Optional[str]:
|
|
||||||
suffixes = path.suffixes
|
|
||||||
if len(suffixes) == 2:
|
|
||||||
variant_label, _ = suffixes
|
|
||||||
else:
|
|
||||||
variant_label = None
|
|
||||||
return variant_label
|
|
||||||
|
|
||||||
|
|
||||||
def get_suffix(path: Path) -> str:
|
|
||||||
suffixes = path.suffixes
|
|
||||||
if len(suffixes) == 2:
|
|
||||||
_, suffix = suffixes
|
|
||||||
else:
|
|
||||||
suffix = suffixes[0]
|
|
||||||
return suffix
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SubfolderCandidate:
|
class SubfolderCandidate:
|
||||||
path: Path
|
path: Path
|
||||||
@ -140,7 +122,7 @@ def _filter_by_variant(files: List[Path], variant: ModelRepoVariant) -> Set[Path
|
|||||||
if path.suffix == ".safetensors":
|
if path.suffix == ".safetensors":
|
||||||
score += 1
|
score += 1
|
||||||
|
|
||||||
candidate_variant_label = get_variant_label(path)
|
candidate_variant_label = path.suffixes[0] if len(path.suffixes) == 2 else None
|
||||||
|
|
||||||
# Some special handling is needed here if there is not an exact match and if we cannot infer the variant
|
# Some special handling is needed here if there is not an exact match and if we cannot infer the variant
|
||||||
# from the file name. In this case, we only give this file a point if the requested variant is FP32 or DEFAULT.
|
# from the file name. In this case, we only give this file a point if the requested variant is FP32 or DEFAULT.
|
||||||
@ -180,76 +162,3 @@ def _filter_by_variant(files: List[Path], variant: ModelRepoVariant) -> Set[Path
|
|||||||
directories[x.parent] = directories.get(x.parent, 0) + 1
|
directories[x.parent] = directories.get(x.parent, 0) + 1
|
||||||
|
|
||||||
return {x for x in result if directories[x.parent] > 1 or x.name != "config.json"}
|
return {x for x in result if directories[x.parent] > 1 or x.name != "config.json"}
|
||||||
|
|
||||||
|
|
||||||
# def _filter_by_variant(files: List[Path], variant: ModelRepoVariant) -> Set[Path]:
|
|
||||||
# """Select the proper variant files from a list of HuggingFace repo_id paths."""
|
|
||||||
# result: set[Path] = set()
|
|
||||||
# basenames: Dict[Path, Path] = {}
|
|
||||||
# for path in files:
|
|
||||||
# if path.suffix in [".onnx", ".pb", ".onnx_data"]:
|
|
||||||
# if variant == ModelRepoVariant.ONNX:
|
|
||||||
# result.add(path)
|
|
||||||
|
|
||||||
# elif "openvino_model" in path.name:
|
|
||||||
# if variant == ModelRepoVariant.OPENVINO:
|
|
||||||
# result.add(path)
|
|
||||||
|
|
||||||
# elif "flax_model" in path.name:
|
|
||||||
# if variant == ModelRepoVariant.FLAX:
|
|
||||||
# result.add(path)
|
|
||||||
|
|
||||||
# elif path.suffix in [".json", ".txt"]:
|
|
||||||
# result.add(path)
|
|
||||||
|
|
||||||
# elif path.suffix in [".bin", ".safetensors", ".pt", ".ckpt"] and variant in [
|
|
||||||
# ModelRepoVariant.FP16,
|
|
||||||
# ModelRepoVariant.FP32,
|
|
||||||
# ModelRepoVariant.DEFAULT,
|
|
||||||
# ]:
|
|
||||||
# parent = path.parent
|
|
||||||
# suffixes = path.suffixes
|
|
||||||
# if len(suffixes) == 2:
|
|
||||||
# variant_label, suffix = suffixes
|
|
||||||
# basename = parent / Path(path.stem).stem
|
|
||||||
# else:
|
|
||||||
# variant_label = ""
|
|
||||||
# suffix = suffixes[0]
|
|
||||||
# basename = parent / path.stem
|
|
||||||
|
|
||||||
# if previous := basenames.get(basename):
|
|
||||||
# if (
|
|
||||||
# previous.suffix != ".safetensors" and suffix == ".safetensors"
|
|
||||||
# ): # replace non-safetensors with safetensors when available
|
|
||||||
# basenames[basename] = path
|
|
||||||
# if variant_label == f".{variant}":
|
|
||||||
# basenames[basename] = path
|
|
||||||
# elif not variant_label and variant in [ModelRepoVariant.FP32, ModelRepoVariant.DEFAULT]:
|
|
||||||
# basenames[basename] = path
|
|
||||||
# else:
|
|
||||||
# basenames[basename] = path
|
|
||||||
|
|
||||||
# else:
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# for v in basenames.values():
|
|
||||||
# result.add(v)
|
|
||||||
|
|
||||||
# # If one of the architecture-related variants was specified and no files matched other than
|
|
||||||
# # config and text files then we return an empty list
|
|
||||||
# if (
|
|
||||||
# variant
|
|
||||||
# and variant in [ModelRepoVariant.ONNX, ModelRepoVariant.OPENVINO, ModelRepoVariant.FLAX]
|
|
||||||
# and not any(variant.value in x.name for x in result)
|
|
||||||
# ):
|
|
||||||
# return set()
|
|
||||||
|
|
||||||
# # Prune folders that contain just a `config.json`. This happens when
|
|
||||||
# # the requested variant (e.g. "onnx") is missing
|
|
||||||
# directories: Dict[Path, int] = {}
|
|
||||||
# for x in result:
|
|
||||||
# if not x.parent:
|
|
||||||
# continue
|
|
||||||
# directories[x.parent] = directories.get(x.parent, 0) + 1
|
|
||||||
|
|
||||||
# return {x for x in result if directories[x.parent] > 1 or x.name != "config.json"}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user