Commit Graph
22 Commits
Author SHA1 Message Date
Claude c6910ab775 Add (word:1.2) weight syntax and PromptLang Inspect node
Weight syntax:
- Grammar: `(arg:SIGNED_NUMBER)` parses to a WeightedGroup
- emph(text|w) is a function-style alias for the same
- Nested weights multiply: ((cat:1.2):0.5) -> 0.6, matching A1111
- Weights are emitted in the (token, weight) tuples that comfy's
  stock encode_token_weights already applies post-transformer

To make per-position weight indexing work, rows are now always
exactly max_length entries: a multi-slot Action emits as one
(action, w) entry followed by (ACTION_CONTINUATION, w) placeholders
that process_tokens drops before handing to super().process_tokens.
This replaces the previous variable-length-row + padding-math.

PromptLang Inspect:
- New node: CLIP + text -> STRING report of per-slot weight, L2
  norm, and top-k nearest vocab tokens for the resolved embedding
- lib/inspect.py uses the wrapper's stored attr name (cond.clip /
  tok.clip) rather than hardcoding 'clip_l', and uses the
  tokenizer's inv_vocab for decode

Fix: parse_numeric_arg now rejects WeightedGroup (was only Action).
SegOrAction widened to include WeightedGroup.
2026-04-12 05:52:06 +00:00
Claude 6fcd3b8a86 Port to current ComfyUI CLIP API and refactor
Rebase the DSL text encoder on comfy.sd1_clip.SDClipModel and
comfy.clip_model.CLIPTextModel_, replacing the old HuggingFace
transformers CLIPTextModel/CLIPTextTransformer/CLIPTextEmbeddings
subclasses (which are no longer how ComfyUI implements CLIP).

Structure:
- Merge lib/action/ into lib/actions/; drop lib/fun_clip_stuff.py
  and the bundled clip_config*.json (comfy ships its own)
- Convert all custom_nodes.KepPromptLang.* absolute imports to
  relative imports so installs via Manager work regardless of
  install directory name

Encoder:
- PromptLangSDClipModel overrides encode_token_weights to walk
  the segment/action tree, assemble [B, seq, hidden] embeds, and
  call self.transformer(None, mask, embeds=..., num_tokens=...)
- posScale / postPos are supported without patching the transformer
  by pre-baking the delta (modified - default) into embeds, so the
  transformer's inline add yields the modified position embedding
- Drop the unused empty-baseline batch that was prepended and then
  sliced off; halves the per-encode forward pass for single prompts

Actions:
- Fix copy-pasted broken __repr__ / depth_repr across sum/diff/avg/
  slerp that referenced fields that didn't exist
- Fix NameError in AverageAction._validate_args (start_arg_token_length)
- Fix class-level mutable state in RandAction
- Unify _parse_scalar / _parse_scalar_weight / _parse_int into a
  single parse_numeric_arg helper in action_utils.py
- Share add_with_broadcast between SumAction and DiffAction
- Convert PostModifiers from TypedDict to dataclass (attribute
  access catches typos that .get() on string keys hides)

Drop the two _exp-pooler / _exp-pooledAvg actions: they recursively
invoked the HF CLIPTextTransformer and would need a rework to fit
the current CLIPTextModel_ interface. They were experimental and
not documented as stable.

BuildGif node:
- Collapse the 10-positional-arg _save_* helpers onto a small
  _SaveContext dataclass
- Stop mutating the input arg semantics (split_every_val was
  reassigned to len(images) when -1)

Tests:
- Add pytest suite covering the parser (grammar, nesting, errors)
  and every action (embedding math, shape, modifier payloads)
- conftest stubs ComfyUI at collection time so tests don't need a
  real ComfyUI install

Drop the broken test_files/ scripts (CI helpers, not a test suite)
and regenerate the README from tools/build_docs.py.
2026-04-12 05:05:58 +00:00
Michael Poutre e002d0ad64 refactor(Action): Update property names to allow automatic doc gen 2023-11-19 00:26:19 -08:00
Michael Poutre dba41a2c4d fix: Drop invalid embeddings during prompt parsing to avoid it later 2023-11-18 22:48:10 -08:00
Michael Poutre fe74c556f5 refactor(PromptTransformer): Simple cleanup and consolidation 2023-11-18 21:36:28 -08:00
Michael Poutre 7e138268f9 chore: Cleanup imports 2023-11-13 19:47:56 -08:00
Michael Poutre ef3f66ef91 refactor/fix: More fixes to align with clip changes in base 2023-11-13 19:47:56 -08:00
Michael Poutre 2f115352ec refactor/fix(SD1): Update for changes to clip handling
Fix end token calculation for long prompts
2023-11-13 19:47:56 -08:00
Michael Poutre e59aaa499d fix(action reg): Don't allow multiple actions with same name 2023-09-04 18:00:35 -07:00
Michael Poutre 6b2bf7485e fix(promptsegment): Put tokens on same device as embeddingmodule weights 2023-08-31 14:19:49 -07:00
Michael Poutre d330663624 fix(promtsegment): Put tokens on the GPU 2023-08-31 14:13:39 -07:00
Michael Poutre 0f36544b0e feat(func): Add Mult 2023-08-31 00:29:58 -07:00
Michael Poutre 9ccf5d2583 feat: Use a more generic grammar to allow for easier interoperability 2023-08-30 23:40:39 -07:00
Michael Poutre f185b39f06 feat(func/rand): Add support for defining range for rand 2023-08-30 21:06:23 -07:00
Michael Poutre af761a5620 feat(func): Add rand(<token_length>) 2023-08-30 20:29:46 -07:00
Michael Poutre fee9c56abd refactor: Rename repo to match github 2023-08-30 18:44:11 -07:00
Michael Poutre bcc083f2fa fix: Use typing.List for backwards compatibility 2023-08-30 18:09:10 -07:00
Michael Poutre 2d2d29bd5a feat: Push new functions 2023-08-25 00:06:17 -07:00
Michael Poutre 4057ff8347 Move build_prompt_segment to parser package 2023-08-25 00:06:17 -07:00
Michael Poutre fc3560be65 refactor: Move core action stuff to lib/action 2023-08-25 00:06:17 -07:00
Michael Poutre 833a027486 refactor: Move PromptSegment to parser module 2023-08-25 00:06:17 -07:00
Michael Poutre 6b8a1ea243 Initial Switch to Lark parser 2023-08-25 00:06:17 -07:00