refiners icon indicating copy to clipboard operation
refiners copied to clipboard

feature: create seamless tileable images in x or y dimension

Open brycedrennan opened this issue 1 year ago • 13 comments

Adds a seamless tile mode but does so in a way you guys probably won't like :-) Opening the pull request to have the discussion.

Tile mode can be set to tile in both directions or only "x" or "y". Set an image as desktop background in tile mode to really get the full effect.

I suspect this will work with SDXL as well but haven't tried it yet.

Examples: 022785_781162360_kdpmpp2m15_PS7 5_white_marble_quartz_with_gold_veins_ generated 284143311-fefd356d-3050-4dfc-89a6-3f30ae8e91ab_reduced_perfect_loop

tiled_image_1_2x3

022755_297564700_kdpmpp2m35_PS7 5_blueberries_ generated 284144042-06c64067-aa5d-4f9f-8b50-d691200c4f75_reduced_perfect_loop tiled_image_2_2x3

022559_809130920_kdpmpp2m35_PS7 5_an_oil_drop_ generated 022559_809130920_kdpmpp2m35_PS7 5_an_oil_drop_ generated _reduced_perfect_loop tiled_image_2x3

brycedrennan avatar Nov 20 '23 06:11 brycedrennan

Also FYI diffusers open feature request for the same feature: https://github.com/huggingface/diffusers/issues/556

brycedrennan avatar Nov 20 '23 06:11 brycedrennan

Awesome idea! To make sure we don't mess with the existing implementation of UNet, we usually work with the Adapter pattern.

Here's how it works:

  1. We'll start by creating a TilingConv2dAdapter that will target a fl.Conv2d. This will wrap the original conv and modify it as needed.
  2. Next, we'll create a TilingAdapter that will target UNets. This will inject the TilingConv2dAdapter into all the conv layers.

Don't worry too much about the naming - it's just a suggestion!

Let me know if you have any questions or need anything else.

limiteinductive avatar Nov 20 '23 10:11 limiteinductive

Great thank you- I'll give it a go.

brycedrennan avatar Nov 20 '23 17:11 brycedrennan

Was revisiting this. Should TilingConv2dAdapter inherit from Adapter? I ask because this assert seems to imply that an Adapter cannot wrap fl.Conv2d since it's not a chain

brycedrennan avatar Dec 19 '23 01:12 brycedrennan

@brycedrennan Adapters can wrap Conv2d, they cannot be a Conv2d (they must subclass Chain). self is the adapter here, the conv would be the adaptee (the generic T). This is similar to SingleLoraAdapter which wraps a linear.

catwell avatar Dec 19 '23 06:12 catwell

Adapters can wrap Conv2d

@brycedrennan FYI, you have such an example part of the UNet: https://github.com/finegrain-ai/refiners/blob/e7892254eb85b06212515b5482a4fa3f699650f8/src/refiners/foundationals/latent_diffusion/stable_diffusion_1/unet.py#L263-L270

deltheil avatar Dec 19 '23 10:12 deltheil

Ah - i see thank you

brycedrennan avatar Dec 19 '23 14:12 brycedrennan

Well I'm pretty sure this is wrong in multiple ways, but it does work. I wasn't quite sure what the "right" way was to wrap the conv2d.

Additionally, it runs roughly .6 it/s slower than the method in the first commit that does not use adapters

brycedrennan avatar Dec 19 '23 23:12 brycedrennan

Well I'm pretty sure this is wrong in multiple ways, but it does work.

Hey @brycedrennan, do you consider it "ready for review" or not?

deltheil avatar Dec 23 '23 09:12 deltheil

@brycedrennan still interested to merge this?

limiteinductive avatar Feb 20 '24 18:02 limiteinductive

Sorry to have let this sit so long. The proposed changes work but are slower than the implementation that directly patches conv2d. I'm not sure why that is but doesn't feel right to propose merging as is.

Since the feature is already working in imaginairy there isn't much urgency on my part. I'd be okay with this pull request being closed or alternatively if you have feedback on it I can continue iterating on it.

brycedrennan avatar Feb 20 '24 18:02 brycedrennan

Maybe what could be done is just having an Adapter on UNet that would patch all Conv2d as a whole instead of wrapping each of them; that would work, too. I have yet to test it myself.

limiteinductive avatar Feb 20 '24 19:02 limiteinductive

okay I'll try that thanks

brycedrennan avatar Feb 20 '24 21:02 brycedrennan