Skip to content

Commit b536f39

Browse files
sayakpaulyiyixuxu
andauthored
[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: YiYi Xu <yixu310@gmail.com>
1 parent e25e525 commit b536f39

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/source/en/using-diffusers/custom_pipeline_overview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,7 @@ pipeline.to("cuda")
239239
prompt = "柴犬、カラフルアート"
240240

241241
image = pipeline(prompt=prompt).images[0]
242+
```
242243

243-
```
244+
> [!TIP]
245+
> 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).

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,6 @@ def download(cls, pretrained_model_name, **kwargs) -> Union[str, os.PathLike]:
13821382

13831383
# Don't download index files of forbidden patterns either
13841384
ignore_patterns = ignore_patterns + [f"{i}.index.*json" for i in ignore_patterns]
1385-
13861385
re_ignore_pattern = [re.compile(fnmatch.translate(p)) for p in ignore_patterns]
13871386
re_allow_pattern = [re.compile(fnmatch.translate(p)) for p in allow_patterns]
13881387

src/diffusers/utils/dynamic_modules_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ def get_cached_module_file(
329329
# The only reason we do the copy is to avoid putting too many folders in sys.path.
330330
shutil.copy(resolved_module_file, submodule_path / module_file)
331331
for module_needed in modules_needed:
332+
if len(module_needed.split(".")) == 2:
333+
module_needed = "/".join(module_needed.split("."))
334+
module_folder = module_needed.split("/")[0]
335+
if not os.path.exists(submodule_path / module_folder):
336+
os.makedirs(submodule_path / module_folder)
332337
module_needed = f"{module_needed}.py"
333338
shutil.copy(os.path.join(pretrained_model_name_or_path, module_needed), submodule_path / module_needed)
334339
else:
@@ -343,9 +348,16 @@ def get_cached_module_file(
343348
create_dynamic_module(full_submodule)
344349

345350
if not (submodule_path / module_file).exists():
351+
if len(module_file.split("/")) == 2:
352+
module_folder = module_file.split("/")[0]
353+
if not os.path.exists(submodule_path / module_folder):
354+
os.makedirs(submodule_path / module_folder)
346355
shutil.copy(resolved_module_file, submodule_path / module_file)
356+
347357
# Make sure we also have every file with relative
348358
for module_needed in modules_needed:
359+
if len(module_needed.split(".")) == 2:
360+
module_needed = "/".join(module_needed.split("."))
349361
if not (submodule_path / module_needed).exists():
350362
get_cached_module_file(
351363
pretrained_model_name_or_path,

0 commit comments

Comments
 (0)