Skip to content

Add orion entry dialect#2330

Merged
copybara-service[bot] merged 1 commit intogoogle:mainfrom
j2kun:orion-dialect
Oct 28, 2025
Merged

Add orion entry dialect#2330
copybara-service[bot] merged 1 commit intogoogle:mainfrom
j2kun:orion-dialect

Conversation

@j2kun
Copy link
Collaborator

@j2kun j2kun commented Oct 17, 2025

Fixes #2328

This corresponds to 3a09186eef73f046d4eff1f32e6ba58f4c8da349 which runs orion and exports ckks + orion dialect MLIR.

From that project, after installing deps, I ran

python examples/mlp.py
python examples/resnet.py  # needs like 60GiB of RAM or lots of swap space, takes about 5m

Then ran the result through heir-opt with this PR (which just extracted type aliases), and persisted the result to the lit tests in this PR

@j2kun j2kun marked this pull request as draft October 17, 2025 21:04
@j2kun j2kun force-pushed the orion-dialect branch 4 times, most recently from 589461d to 2b47779 Compare October 22, 2025 03:58
@j2kun j2kun requested a review from asraa October 22, 2025 03:59
@j2kun
Copy link
Collaborator Author

j2kun commented Oct 22, 2025

CC @eymay

@j2kun j2kun marked this pull request as ready for review October 22, 2025 04:10
Copy link
Contributor

@eymay eymay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding Orion frontend support. The PR looks clean to me, I pointed out some limitations of the translator in comments.

@j2kun
Copy link
Collaborator Author

j2kun commented Oct 22, 2025

@eymay I did find it a bit strange that all the chebyshev ops emitted have a domain start/end as -1, 1 exactly, rather than some domain specific to the network/data distribution. Is that what you observed as well? Or does it indicate a bug on my part?

@j2kun
Copy link
Collaborator Author

j2kun commented Oct 22, 2025

@eymay sorry to keep bugging you again, but I also noticed that the bsgs_ratio is always 2, and I can't find anywhere in the Orion codebase that sets this value to a non-hard-coded-2. Did you notice the same?

@eymay
Copy link
Contributor

eymay commented Oct 23, 2025

@eymay I did find it a bit strange that all the chebyshev ops emitted have a domain start/end as -1, 1 exactly, rather than some domain specific to the network/data distribution. Is that what you observed as well? Or does it indicate a bug on my part?

I think this is a desired result from the Orion compilation, this is to ensure a stable polynomial approximation. So Orion normalizes the data distribution for polynomial approximation, from the Orion paper:

Range estimation: Both high-precision bootstrapping and
high-degree (Chebyshev) polynomial activation functions
require the inputs to be in the range [−1, 1].
Prior work chooses per network scaling factors by man-
ually inspecting and tracking the largest intermediate val-
ues seen [41, 52]. Orion handles this process automatically
through net.fit(), which accepts the entire training dataset
as input, calculates per layer scaling factors, and inserts scale-
down multiplications directly into the computational graph.

My default approach for the attributes in the Orion internal IR was to preserve them in the MLIR IR so they become explicit even if we don't end up using them.

@eymay
Copy link
Contributor

eymay commented Oct 23, 2025

@eymay sorry to keep bugging you again, but I also noticed that the bsgs_ratio is always 2, and I can't find anywhere in the Orion codebase that sets this value to a non-hard-coded-2. Did you notice the same?

Please I appreciate the discussion. Yes Orion seems to just keep bsgs_ratio=2 for all the layers like Linear, AvgPool2d and Conv2d. On top of that the translator also emits the same number if there is no attribute found for the op. The ratio plugs into Lattigo's LogBabyStepGiantStepRatio parameter explained here. It seems like a heuristic number that stayed on but we don't need to take it into account while lowering.

@j2kun
Copy link
Collaborator Author

j2kun commented Oct 23, 2025

Ok, one change I want to make before this PR is submitted is to have the plaintext arguments be cleartext-typed, so that the function encodes them as plaintexts at runtime. This is not optimal, but we need the ability to rotate the plaintexts for the purpose of BSGS (to my knowledge none of these libraries support rotating an encoded plaintext; decoding just to rotate and re-encode seems silly). While we could pre-rotate the diagonals Orion produces in a manner specific to HEIR's implementation of BSGS, it seems quite brittle, and I suspect the runtime hit will not be that bad...

@j2kun j2kun added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Oct 28, 2025
@copybara-service copybara-service bot merged commit 14c43c6 into google:main Oct 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an Orion entry dialect

3 participants