lnccbrown / lnccbrown/LANfactory

JAX MLP activation list can be smaller than layer list (index misalignment)

Open Beginner friendly
#105 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
16
Forks
4
Avg merge
3d 7h
Merged PRs (30d)
8

Description

In jax_mlp.py, `self.layers` is built with one entry per layer, but `self.activation_funs` filters out `"linear"` activations.

https://github.com/lnccbrown/LANfactory/blob/9301939e8fed95ee966bf41fe71bb68bd620d7fd/src/lanfactory/trainers/jax_mlp.py#L97-L101

That means `self.activation_funs` can be shorter than `self.layers`.
Later, forward indexes `self.activation_funs[i]` using the layer index, which can raise `IndexError` or apply the wrong activation when `"linear"` appears before the final layer.

```python
def test_mlp_jax_with_linear_hidden_activation():
model = JaxMLP(
layer_sizes=[10, 10, 1],
activations=["tanh", "linear", "linear"],
train_output_type="logprob",
train=True,
)

rng = jax.random.PRNGKey(0)
test_input = jnp.ones((5, 6))
params = model.init(rng, test_input) # fails with IndexError in old pattern
output = model.apply(params, test_input)

assert output.shape == (5, 1)
```

Observed failure:
`IndexError: tuple index out of range` at jax_mlp.py

Expected:
Activation mapping should stay layer-aligned even when `"linear"` is used in hidden layers.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/lanfactory/trainers/jax_mlp.py at the activation-list construction around lines 97–101, then trace how forward indexes activations by layer. Use the provided test_mlp_jax_with_linear_hidden_activation case with the shown JAXMLP configuration. Done means linear hidden activations remain layer-aligned and the model initializes, applies, and produces output with shape (5, 1).

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.