Skip to content

fix: support {, } and \ in dict keys of differentiable fields - #78

Merged
dionhaefner merged 4 commits into
mainfrom
dion/escape-dict-keys
Oct 21, 2026
Merged

dionhaefner merged 4 commits into
mainfrom
dion/escape-dict-keys

Conversation

@dionhaefner

Copy link
Copy Markdown
Contributor

Relevant issue or PR

Stacked on #73, since it needs tesseract-core 1.15, which #73 requires. Merge after #73.

Description of changes

A differentiable leaf inside a dict[str, Differentiable[...]] field is named params.{key} in gradient requests. tesseract-core 1.15 requires {, } and \ in the key to be backslash-escaped there. tesseract-torch sent such keys unescaped, so their backward pass failed with a validation error:

out = apply_tesseract(tess, {"params": {"a{b": x}})
out["y"].sum().backward()  # raised a ValidationError, now computes x.grad

Keys without these characters are sent as before. A key spelled {} used to be mistaken for the template itself; it is now escaped like any other concrete key.

Testing done

  • New unit tests for the escaped wire names, and the existing end-to-end gradient test for dict keys now also covers a{b, a}b, {} and a\b.
  • Locally against tesseract-core 1.15.0, these tests pass with the fix and the four new keys fail without it.

…ansport works

apply_tesseract no longer takes gpu_transport. A call with CUDA tensors asks
Tesseract.resolve_gpu_transport() which transport to use. This needs
tesseract-core 1.15, which also removed the client internals the previous
implementation switched per call, so the floor rises to >=1.15.0.
tesseract-core 1.15 requires {, } and \ in a dict key to be
backslash-escaped inside the key's {...} path segment.
@PasteurBot

PasteurBot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results

Benchmarks measure tesseract-torch execution time using noop and vectoradd Tesseracts.

🚀 0 faster, ⚠️ 0 slower, ✅ 16 unchanged

✅ No significant performance changes detected.

Full results
Benchmark Baseline Current Change Status
noop_api/apply_1,000 0.789ms 0.796ms +0.9% ✅
noop_api/apply_100,000 0.813ms 0.821ms +1.0% ✅
noop_api/apply_1,000,000 0.921ms 0.961ms +4.4% ✅
noop_api/apply_10,000,000 5.893ms 5.917ms +0.4% ✅
noop_api/cast_float64_1,000 0.803ms 0.817ms +1.7% ✅
noop_api/cast_float64_100,000 0.855ms 0.866ms +1.3% ✅
noop_api/cast_float64_1,000,000 1.152ms 1.205ms +4.6% ✅
noop_api/cast_float64_10,000,000 13.680ms 13.615ms -0.5% ✅
vectoradd_api/apply_1,000 0.839ms 0.848ms +1.1% ✅
vectoradd_api/apply_100,000 0.879ms 0.891ms +1.3% ✅
vectoradd_api/apply_1,000,000 1.156ms 1.164ms +0.7% ✅
vectoradd_api/apply_10,000,000 12.739ms 12.838ms +0.8% ✅
vectoradd_api/backward_1,000 1.775ms 1.778ms +0.2% ✅
vectoradd_api/backward_100,000 1.976ms 1.970ms -0.3% ✅
vectoradd_api/backward_1,000,000 3.120ms 3.208ms +2.8% ✅
vectoradd_api/backward_10,000,000 29.049ms 31.892ms +9.8% ✅

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (176e85b) to head (24972f1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #78      +/-   ##
==========================================
+ Coverage   90.05%   90.30%   +0.24%     
==========================================
  Files           2        2              
  Lines         362      361       -1     
  Branches       67       66       -1     
==========================================
  Hits          326      326              
  Misses         12       12              
+ Partials       24       23       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from dion/resolve-gpu-transport to main October 21, 2026 07:14
Comment thread tests/test_edge_cases.py Resolved
@dionhaefner
dionhaefner merged commit 8c14c15 into main Oct 21, 2026
21 checks passed
@dionhaefner
dionhaefner deleted the dion/escape-dict-keys branch October 21, 2026 14:07
@pasteurlabs pasteurlabs locked and limited conversation to collaborators Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants