Skip to content

Commit a23e10c

Browse files
committed
Refine audit categorization and documentation for dual_use and safe paths in JAX and Flax
1 parent 793732b commit a23e10c

7 files changed

Lines changed: 447 additions & 42 deletions

File tree

packages/syft-restrict/docs/blacklist.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ disallow_functions=[
271271
# multi-host / distributed — outbound network connections
272272
"jax.distributed.*", "jax.monitoring.*", "jax.experimental.multihost_utils.*",
273273
# FFI / interop
274-
"jax.dlpack.*", "jax.ffi*",
274+
"jax.dlpack.*", "jax.ffi.*",
275275
# array <-> disk (save/savez/savez_compressed/savetxt, load/loadtxt, tofile/fromfile/memmap)
276276
"jax.numpy.save*", "jax.numpy.load*", "*.tofile", "*.fromfile", "*.memmap",
277277
# checkpointing / serialization (write to disk, incl. gs://)

packages/syft-restrict/src/syft_restrict/audit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
1212
- ``"unsafe"`` — matches a catalog entry for known disk/network/host-callback surface, OR is a glob
1313
(``jax.*``) that grants a whole namespace. Remove it or tighten the allow.
14-
- ``"dual_use"`` — a useful, mostly-safe op that can still be abused in combination (e.g. ``einsum``,
15-
``softmax``, ``where``). Allowed, but flagged: the *category itself* carries the "handle with care"
16-
signal, so entry notes stay terse and vague — never an abuse how-to.
17-
- ``"safe"`` — matches a curated entry for a genuinely inert path (constants, masks, module refs) with
18-
no residual output channel of its own.
14+
- ``"safe"`` — pure computation: ordinary math (``einsum``, ``matmul``, activations, reductions,
15+
comparisons, reshapes), constants, RNG, and initializers.
16+
- ``"dual_use"`` — a path flagged for a specific capability beyond pure computation; each entry
17+
states its own concrete reason (e.g. crossing the host/device boundary, or widening what the
18+
verifier accepts as valid attribute access).
1919
- ``"review"`` — none of the above. The audit makes **no** guess about it: it is reported as
2020
uncatalogued and deferred to human review. Unknowns are never assumed safe.
2121

packages/syft-restrict/src/syft_restrict/catalog/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ catalog/
2020
`0.19`. **There is no version-agnostic fallback per library:** if no version dir matches the
2121
installed version, that library contributes no rules and its paths fall to `review`. Add a version
2222
dir to cover a release.
23-
- `_common/default/catalog.json` is always merged in (its `default` segment is a fixed name, not a
24-
version). It holds truly cross-library patterns (`*.io_callback`, `*.tofile`, …) and blanket rules
23+
- `_common/default/catalog.json` is always merged in. It holds truly cross-library patterns (`*.io_callback`, `*.tofile`, …) and blanket rules
2524
for libraries whose import root cannot be version-keyed (e.g. `orbax`: the `orbax` import root is a
2625
namespace package with no `__version__`; the distribution is `orbax-checkpoint`).
2726

@@ -33,16 +32,21 @@ Each `catalog.json` is:
3332
{
3433
"_about": "free-text note",
3534
"unsafe": { "<dotted-path glob>": "why it is unsafe" },
36-
"dual_use": { "<dotted-path glob>": "what the op is (terse; the category carries the caution)" },
37-
"safe": { "<dotted-path glob>": "why it is genuinely inert" }
35+
"dual_use": { "<dotted-path glob>": "the concrete reason it is flagged" },
36+
"safe": { "<dotted-path glob>": "what the op is (terse)" }
3837
}
3938
```
4039

4140
- `unsafe` = known disk/network/host-callback surface.
42-
- `dual_use` = a useful op that is mostly safe but can be **abused in combination** (`einsum`,
43-
`softmax`, `where`, …). Allowed but flagged. The *category* is the caution, so keep each note a
44-
terse description of what the op is — do **not** spell out abuse mechanics (no how-to).
45-
- `safe` = genuinely inert (constants, masks, module refs) with no residual channel of its own.
41+
- `safe` = pure computation: ordinary math (`einsum`, `matmul`, activations, reductions, reshapes),
42+
constants, RNG, and initializers.
43+
- `dual_use` = a path flagged for a specific capability beyond pure computation. Each entry must
44+
state its own concrete reason (e.g. crossing the host/device boundary).
4645

4746
A path is matched strictest-first (`unsafe``dual_use``safe`). Anything matched by none defaults
4847
to `review` — never silently to `safe`.
48+
49+
> [!Note]
50+
>
51+
> `safe` means "no disk/network/host-callback capability", not "no information
52+
> flow". The catalog lists capabilities, not guarantees.

packages/syft-restrict/src/syft_restrict/catalog/_common/default/catalog.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"_about": "Library-agnostic risk rules, merged into every path's audit regardless of library or version. Patterns are dotted-path globs (fnmatch); 'unsafe' = disk/network/host-callback. Also holds blanket rules for libraries whose import root cannot be version-keyed (e.g. orbax: the 'orbax' import root is a namespace package with no __version__; the distribution is orbax-checkpoint). This is advisory, not a proof.",
33
"unsafe": {
44
"*.fromfile": "Reads raw bytes from a file on disk.",
5-
"*.host_callback*": "Legacy host-callback API — runs host Python.",
65
"*.io_callback": "Runs a host Python callback with side effects (I/O).",
76
"*.memmap": "Memory-maps a file on disk.",
87
"*.tofile": "Writes raw array bytes to a file on disk.",

packages/syft-restrict/src/syft_restrict/catalog/flax/0.12/catalog.json

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,104 @@
11
{
2-
"_about": "Risk rules for flax 0.12.x. 'unsafe' = disk/network/host-callback; 'dual_use' = useful surface that is mostly safe but can be abused in combination (the category itself is the caution, so notes stay terse and vague); 'safe' = genuinely inert. Cross-library rules in _common/default are merged in on top of these. This is advisory, not a proof.",
2+
"_about": "Risk rules for flax 0.12.x. 'unsafe' = disk/network/host-callback; 'safe' = pure computation; 'dual_use' = flagged for a specific capability beyond pure computation, reason stated per entry. Covers the commonly-used flax.linen surface; anything uncatalogued falls through to 'review'. Cross-library rules in _common/default are merged in on top of these. This is advisory, not a proof.",
33
"dual_use": {
4-
"flax.linen.Module": "Flax module base class; required to define a model. Keep allow_base_class_attributes=False to require explicit assignment."
4+
"flax.linen.Module": "Flax module base class; required to define a model. allow_base_class_attributes widens what the verifier treats as valid attribute access — keep it False to require explicit assignment."
5+
},
6+
"safe": {
7+
"flax.linen.BatchNorm": "Batch normalization.",
8+
"flax.linen.Bidirectional": "Bidirectional wrapper running a cell forward and backward.",
9+
"flax.linen.Conv": "Convolution layer.",
10+
"flax.linen.ConvLSTMCell": "Convolutional LSTM cell.",
11+
"flax.linen.ConvLocal": "Locally-connected (unshared-weight) convolution layer.",
12+
"flax.linen.ConvTranspose": "Transposed (fractionally-strided) convolution layer.",
13+
"flax.linen.Dense": "Fully-connected (dense) layer.",
14+
"flax.linen.DenseGeneral": "Dense layer contracting over arbitrary axes.",
15+
"flax.linen.Dropout": "Stochastic dropout layer.",
16+
"flax.linen.Einsum": "Einsum layer with a learned operand.",
17+
"flax.linen.Embed": "Embedding lookup layer.",
18+
"flax.linen.GRUCell": "GRU recurrent cell.",
19+
"flax.linen.GroupNorm": "Group normalization.",
20+
"flax.linen.InstanceNorm": "Instance normalization.",
21+
"flax.linen.LSTMCell": "LSTM recurrent cell.",
22+
"flax.linen.LayerNorm": "Layer normalization.",
23+
"flax.linen.MultiHeadAttention": "Multi-head attention layer.",
24+
"flax.linen.MultiHeadDotProductAttention": "Multi-head dot-product attention layer.",
25+
"flax.linen.OptimizedLSTMCell": "LSTM cell with a fused implementation.",
26+
"flax.linen.PReLU": "Parametric-ReLU activation layer.",
27+
"flax.linen.Partitioned": "Sharding-metadata wrapper for a parameter; structural annotation.",
28+
"flax.linen.RMSNorm": "Root-mean-square layer normalization.",
29+
"flax.linen.RNN": "Recurrent layer applying a cell over a sequence.",
30+
"flax.linen.SelfAttention": "Multi-head self-attention layer.",
31+
"flax.linen.Sequential": "Container applying sub-layers in order; the sub-layers are allow-listed separately.",
32+
"flax.linen.SimpleCell": "Elman (simple) recurrent cell.",
33+
"flax.linen.SpectralNorm": "Spectral-normalization wrapper.",
34+
"flax.linen.Variable": "Handle to a module variable; a state reference, not compute or IO.",
35+
"flax.linen.WeightNorm": "Weight-normalization wrapper.",
36+
"flax.linen.avg_pool": "Average pooling over windows.",
37+
"flax.linen.celu": "CELU activation.",
38+
"flax.linen.checkpoint": "Rematerialization transform (alias of remat); not disk checkpointing.",
39+
"flax.linen.combine_masks": "Combines boolean masks with logical AND.",
40+
"flax.linen.compact": "Decorator marking a module's inline-submodule method; structural.",
41+
"flax.linen.cond": "Lifted conditional executing one of two branches.",
42+
"flax.linen.dot_product_attention": "Dot-product attention function.",
43+
"flax.linen.dot_product_attention_weights": "Dot-product attention weights (softmax over scores).",
44+
"flax.linen.elu": "ELU activation.",
45+
"flax.linen.gelu": "GELU activation.",
46+
"flax.linen.glu": "Gated-linear-unit activation.",
47+
"flax.linen.hard_sigmoid": "Hard-sigmoid activation.",
48+
"flax.linen.hard_silu": "Hard-SiLU / hard-swish activation.",
49+
"flax.linen.hard_swish": "Hard-swish / hard-SiLU activation.",
50+
"flax.linen.hard_tanh": "Hard-tanh activation.",
51+
"flax.linen.initializers.constant": "Constant-value parameter initializer.",
52+
"flax.linen.initializers.delta_orthogonal": "Delta-orthogonal initializer for convolution kernels.",
53+
"flax.linen.initializers.glorot_normal": "Glorot (Xavier) normal initializer.",
54+
"flax.linen.initializers.glorot_uniform": "Glorot (Xavier) uniform initializer.",
55+
"flax.linen.initializers.he_normal": "He (Kaiming) normal initializer.",
56+
"flax.linen.initializers.he_uniform": "He (Kaiming) uniform initializer.",
57+
"flax.linen.initializers.kaiming_normal": "Kaiming (He) normal initializer.",
58+
"flax.linen.initializers.kaiming_uniform": "Kaiming (He) uniform initializer.",
59+
"flax.linen.initializers.lecun_normal": "LeCun normal initializer.",
60+
"flax.linen.initializers.lecun_uniform": "LeCun uniform initializer.",
61+
"flax.linen.initializers.normal": "Normal-distribution parameter initializer.",
62+
"flax.linen.initializers.ones": "All-ones parameter initializer.",
63+
"flax.linen.initializers.orthogonal": "Orthogonal-matrix parameter initializer.",
64+
"flax.linen.initializers.truncated_normal": "Truncated-normal parameter initializer.",
65+
"flax.linen.initializers.uniform": "Uniform-distribution parameter initializer.",
66+
"flax.linen.initializers.variance_scaling": "Variance-scaling parameter initializer.",
67+
"flax.linen.initializers.xavier_normal": "Xavier (Glorot) normal initializer.",
68+
"flax.linen.initializers.xavier_uniform": "Xavier (Glorot) uniform initializer.",
69+
"flax.linen.initializers.zeros": "All-zeros parameter initializer.",
70+
"flax.linen.jit": "Lifted JIT compilation of a module.",
71+
"flax.linen.leaky_relu": "Leaky-ReLU activation.",
72+
"flax.linen.log_sigmoid": "Log-sigmoid activation.",
73+
"flax.linen.log_softmax": "Log-softmax activation.",
74+
"flax.linen.logsumexp": "Log-sum-exp reduction.",
75+
"flax.linen.make_attention_mask": "Builds an attention mask by broadcasting a query/key position comparison.",
76+
"flax.linen.make_causal_mask": "Builds a causal (lower-triangular) attention mask from a shape.",
77+
"flax.linen.map_variables": "Transform mapping over a module's variable collections.",
78+
"flax.linen.max_pool": "Max pooling over windows.",
79+
"flax.linen.nowrap": "Decorator opting a method out of module auto-wrapping; structural.",
80+
"flax.linen.one_hot": "One-hot encoding of integer indices.",
81+
"flax.linen.pool": "Generic windowed pooling reduction.",
82+
"flax.linen.relu": "ReLU activation.",
83+
"flax.linen.relu6": "ReLU6 activation.",
84+
"flax.linen.remat": "Rematerialization (gradient-checkpointing) transform.",
85+
"flax.linen.remat_scan": "Rematerialized scan transform.",
86+
"flax.linen.scan": "Lifted scan over a module along an axis.",
87+
"flax.linen.selu": "SELU activation.",
88+
"flax.linen.sigmoid": "Sigmoid activation.",
89+
"flax.linen.silu": "SiLU / swish activation.",
90+
"flax.linen.soft_sign": "Soft-sign activation.",
91+
"flax.linen.softmax": "Softmax activation.",
92+
"flax.linen.softplus": "Softplus activation.",
93+
"flax.linen.standardize": "Standardizes to zero-mean, unit-variance along an axis.",
94+
"flax.linen.swish": "Swish / SiLU activation.",
95+
"flax.linen.switch": "Lifted multi-branch switch.",
96+
"flax.linen.tanh": "Hyperbolic-tangent activation.",
97+
"flax.linen.vmap": "Lifted vectorizing map over a module.",
98+
"flax.linen.while_loop": "Lifted while loop."
599
},
6100
"unsafe": {
101+
"flax.io.*": "File IO shim — reads/writes files on disk (and gs:// cloud storage when available).",
7102
"flax.serialization.*": "Serializes model state to bytes / disk.",
8103
"flax.training.checkpoints.*": "Writes / reads checkpoints to disk (path accepts gs://)."
9104
}

0 commit comments

Comments
 (0)