Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update batch_hijack.py #1772

Closed
wants to merge 1 commit into from
Closed

Update batch_hijack.py #1772

wants to merge 1 commit into from

Conversation

apsntian
Copy link

@apsntian apsntian commented Jul 7, 2023

change the comparison method of InputMode

I'm modifying the webui code to use controlnet+adetailer as rest api, I found that this code causes problem.

The problem is the class variable of InputMode is instantiated for each thread (UI and Rest API), so the comparison from Rest API doesn't work properly. In Python, it is not regarded as string, so the comparison is done with their id. so I changed the comparison code into just simple string comparison.

change the comparison method of InputMode 

I'm modifying the webui code to use controlnet+adetailer as rest api, I found that this code causes problem. 

The problem is the class variable of InputMode is instantiated for each thread (UI and Rest API), so the comparison from Rest API doesn't work properly. In Python, it is not regarded as string, so the comparison is done with their id.  so I changed the comparison code into just simple string comparison.
@huchenlei
Copy link
Collaborator

I don’t think it is because different thread will reinitialize the variable. This is a module reload problem similar to ControlNetUnit issue we had earlier.

The comparison fail is also not because of ID comparison. It’s because the new class of input mode is different from the old input mode class.

If input mode is constructed within ControlNet’s scope, we should find a place to do proper module reload instead of comparing string values.

Note: a1111 has claimed to do the proper module reloading now after 1.4.0. Should we get rid of all module reload code so they don’t cause us troubles?

@ljleb @lllyasviel

@huchenlei huchenlei requested a review from ljleb July 7, 2023 15:00
@huchenlei
Copy link
Collaborator

The problem the user is facing is probably user script import input mode before controlnet.py reload batchhijack module. This will create 2 versions of input mode class.

@ljleb
Copy link
Collaborator

ljleb commented Jul 8, 2023

These double definitions are a bit annoying.

Note: a1111 has claimed to do the proper module reloading now after 1.4.0. Should we get rid of all module reload code so they don’t cause us troubles?

I think this is fine. The reload button in the extensions tab was also replaced by "apply and quit".

As we don't need to reload the modules now, a fix is to move all definitions of external_code.py to another file, i.e. internal_controlnet/external_code.py and then import * from that file. This should ensure that module caching from python will work properly.

@ljleb
Copy link
Collaborator

ljleb commented Jul 8, 2023

@apsntian can you verify that #1775 fixes the issue? It has been merged in main just now.

@apsntian
Copy link
Author

apsntian commented Jul 8, 2023

@apsntian can you verify that #1775 fixes the issue? It has been merged in main just now.

I checked that #1775 fixes my issue. Thanks a lot!

@huchenlei huchenlei closed this Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants