File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33`KerasHubForCausalLM` lives here in keras-hub and is registered with
44tpu-inference's model registry (and vLLM's) by tpu-inference's plugin hook,
55so the native `flax_nnx` loader resolves it by architecture name like any
6- other model. It is only ever imported on the serving path, where flax and
7- tpu-inference are installed.
6+ other model. It is only ever instantiated on the serving path, where flax
7+ and tpu-inference are installed; importing it works anywhere (api-gen walks
8+ every module), with the nnx base class swapped in only when flax exists.
89"""
910
1011import jax
11- from flax import nnx
1212from jax .sharding import Mesh
1313from keras import ops
1414
15+ try :
16+ from flax import nnx
17+
18+ _NnxModule = nnx .Module
19+ except ImportError : # flax is only present on the serving path
20+ _NnxModule = object
21+
1522from keras_hub .src .models .causal_lm import CausalLM
1623from keras_hub .src .vllm .context import get_vllm_context
1724from keras_hub .src .vllm .context import vllm_context_scope
1825
1926
20- class KerasHubForCausalLM (nnx . Module ):
27+ class KerasHubForCausalLM (_NnxModule ):
2128 """Serves a KerasHub `CausalLM` on tpu-inference's native JAX path.
2229
2330 An adapter, not a conversion: it implements the model interface the
You can’t perform that action at this time.
0 commit comments