crowsonkb / k-diffusion

Karras et al. (2022) diffusion models for PyTorch
MIT License
2.21k stars 371 forks source link

Eliminate jsonmerge dependency #73

Open pharmapsychotic opened 1 year ago

pharmapsychotic commented 1 year ago

A change for your consideration which removes the jsonmerge dependency.

The jsonmerge library depends on the Rust persistent data structures rpds library which can only be imported into a process once. This creates a problem if you have an application which uses multiple libraries that each use k-diffusion (like diffusers + stablecore for example) and results in PyO3 modules may only be initialized once per interpreter process exception on the second time k-diffusion gets imported.

Since jsonmerge is only used to merge config settings with default settings, this change replaces it with a small equivalent merge_config function.

akx commented 1 year ago

FWIW, jsonmerge only depends on rpds because newer versions of jsonschema (4.18.0+) depend on it.

You can install jsonschema<4.18.0 to not require rpds, which is what jsonmerge==1.9.1 does: https://github.com/avian2/jsonmerge/commit/c002c91e40a141e1da84ed54e037f4bdce1031f9

That said, a dependency chain less in favor of 10 lines of code is a win in my books 😁

akx commented 5 months ago

@pharmapsychotic Could you rebase this to fix the conflict? Might eventually get this merged.. 😅