OneTrainer icon indicating copy to clipboard operation
OneTrainer copied to clipboard

Custom layer filters that support regular expressions

Open tehybel opened this issue 8 months ago • 1 comments

Old-style literal filters are still supported, since they are valid regular expressions, too.

tehybel avatar Apr 09 '25 12:04 tehybel

  • printing to the console which layers were selected (and which not) would be helpful imho
  • when this is done I might want to use it for a PR to filter layers in full finetuning. Finetuning some layers such as the embedders seems counterproductive

dxqb avatar Apr 30 '25 09:04 dxqb

Given Thomas has been MIA for awhile now I have gone and refactored it.

@dxqbYD Added logging of the selected/unselected layers/

O-J1 avatar Jun 21 '25 10:06 O-J1

Here https://github.com/Nerogar/OneTrainer/blob/d472c65a66fa71e5e05babc3c02202882cfc079e/modules/modelSetup/ChromaFineTuneSetup.py#L49 is now code that applies a layer filter to full tinetuning - although technically requires_grad should also set to False for these parameters

dxqb avatar Aug 25 '25 00:08 dxqb

one possible solution for the some of the complications above: do we really need regex? why not a simpler substring matching, and an "ignore pattern" that allows to exclude certain layers

dxqb avatar Aug 25 '25 17:08 dxqb

I think that would allow filtering of “single” for the flux-ish models (flux, Hunyuan, i assume Chroma) to only grab a double block(s).

Calamdor avatar Aug 25 '25 17:08 Calamdor

I think that would allow filtering of “single” for the flux-ish models (flux, Hunyuan, i assume Chroma) to only grab a double block(s).

yes. any other use cases that would really require regex?

dxqb avatar Aug 25 '25 17:08 dxqb

I think that would allow filtering of “single” for the flux-ish models (flux, Hunyuan, i assume Chroma) to only grab a double block(s).

yes. any other use cases that would really require regex?

I think that would allow filtering of “single” for the flux-ish models (flux, Hunyuan, i assume Chroma) to only grab a double block(s).

yes. any other use cases that would really require regex?

Anyone wanting to to select multiple non-contiguous blocks or complex layer selection. Comma delimited lists still work fine and that was the intention of this

image

O-J1 avatar Aug 28 '25 12:08 O-J1

yes. any other use cases that would really require regex?

Anyone wanting to to select multiple non-contiguous blocks or complex layer selection. Comma delimited lists still work fine and that was the intention of this image

okay, if we want to support regex let's do that for expert users, but following the same sentiment as your screenshot quote I'd like a way to reject a pattern for non-expert users. I'd consider myself among those non-expert users, considering how difficult it is to reject something using regex:

^(?:(?!guidance_layer|context_embedder|x_embed).)*$

What do you think about:

  • keep the current lora_layers (but rename it to layers_accept either in this PR or in a later one, because we also need it for FFT)
  • add a [lora_]layers_reject for simple substring pattern matching to reject layers
  • both can be used as regex if you switch it on

This solves the complexity, but also this https://github.com/Nerogar/OneTrainer/pull/778#discussion_r2293132065 because we don't need regex presets anymore.

dxqb avatar Aug 28 '25 14:08 dxqb

This solves the complexity, ... don't need regex presets anymore.

Sumarising convo on Discord:

  1. Regex presets are already supported
  2. We agreed substring matching would be better as the default, to be contributed in a seperate PR (new UI field)

I believe all review comments have been addressed now or are relevant to a new PR

O-J1 avatar Aug 28 '25 16:08 O-J1