Unverified Commit b536f398 authored by Sayak Paul's avatar Sayak Paul Committed by GitHub
Browse files

[Custom Pipelines with Custom Components] fix multiple things (#7304)



* checking to improve pipelines.

* more fixes.

* add: tip to encourage the usage of revision

* Apply suggestions from code review

* retrigger ci

---------
Co-authored-by: default avatarYiYi Xu <yixu310@gmail.com>
parent e25e525f
...@@ -239,5 +239,7 @@ pipeline.to("cuda") ...@@ -239,5 +239,7 @@ pipeline.to("cuda")
prompt = "柴犬、カラフルアート" prompt = "柴犬、カラフルアート"
image = pipeline(prompt=prompt).images[0] image = pipeline(prompt=prompt).images[0]
``` ```
> [!TIP]
> When using `trust_remote_code=True`, it is also strongly encouraged to pass a commit hash as a `revision` to make sure the author of the models did not update the code with some malicious new lines (unless you fully trust the authors of the models).
\ No newline at end of file
...@@ -1382,7 +1382,6 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin): ...@@ -1382,7 +1382,6 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
# Don't download index files of forbidden patterns either # Don't download index files of forbidden patterns either
ignore_patterns = ignore_patterns + [f"{i}.index.*json" for i in ignore_patterns] ignore_patterns = ignore_patterns + [f"{i}.index.*json" for i in ignore_patterns]
re_ignore_pattern = [re.compile(fnmatch.translate(p)) for p in ignore_patterns] re_ignore_pattern = [re.compile(fnmatch.translate(p)) for p in ignore_patterns]
re_allow_pattern = [re.compile(fnmatch.translate(p)) for p in allow_patterns] re_allow_pattern = [re.compile(fnmatch.translate(p)) for p in allow_patterns]
......
...@@ -329,6 +329,11 @@ def get_cached_module_file( ...@@ -329,6 +329,11 @@ def get_cached_module_file(
# The only reason we do the copy is to avoid putting too many folders in sys.path. # The only reason we do the copy is to avoid putting too many folders in sys.path.
shutil.copy(resolved_module_file, submodule_path / module_file) shutil.copy(resolved_module_file, submodule_path / module_file)
for module_needed in modules_needed: for module_needed in modules_needed:
if len(module_needed.split(".")) == 2:
module_needed = "/".join(module_needed.split("."))
module_folder = module_needed.split("/")[0]
if not os.path.exists(submodule_path / module_folder):
os.makedirs(submodule_path / module_folder)
module_needed = f"{module_needed}.py" module_needed = f"{module_needed}.py"
shutil.copy(os.path.join(pretrained_model_name_or_path, module_needed), submodule_path / module_needed) shutil.copy(os.path.join(pretrained_model_name_or_path, module_needed), submodule_path / module_needed)
else: else:
...@@ -343,9 +348,16 @@ def get_cached_module_file( ...@@ -343,9 +348,16 @@ def get_cached_module_file(
create_dynamic_module(full_submodule) create_dynamic_module(full_submodule)
if not (submodule_path / module_file).exists(): if not (submodule_path / module_file).exists():
if len(module_file.split("/")) == 2:
module_folder = module_file.split("/")[0]
if not os.path.exists(submodule_path / module_folder):
os.makedirs(submodule_path / module_folder)
shutil.copy(resolved_module_file, submodule_path / module_file) shutil.copy(resolved_module_file, submodule_path / module_file)
# Make sure we also have every file with relative # Make sure we also have every file with relative
for module_needed in modules_needed: for module_needed in modules_needed:
if len(module_needed.split(".")) == 2:
module_needed = "/".join(module_needed.split("."))
if not (submodule_path / module_needed).exists(): if not (submodule_path / module_needed).exists():
get_cached_module_file( get_cached_module_file(
pretrained_model_name_or_path, pretrained_model_name_or_path,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment