neural-network-building-blocks
Use this sub-skill for MLAlgorithms NeuralNet construction, activations, losses, parameters, constraints, regularizers, optimizers, convolutional/recurrent layers, and DQN wiring.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- neural-network-building-blocks
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use this sub-skill for MLAlgorithms NeuralNet construction, activations, losses, parameters, constraints, regularizers, optimizers, convolutional/recurrent layers, and DQN wiring.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/api-reference.md6.2 KB
- 参考文档references/neural-workflows.md2.9 KB
- 参考文档references/rl-dqn.md2.4 KB
- 参考文档references/troubleshooting.md3.4 KB
- 参考文档references/workflows.md4.2 KB
- 脚本scripts/run_neural_smoke.py3.8 KB
03 SKILL.md 正文
Neural Network Building Blocks
Use this sub-skill when a task asks for the custom MLAlgorithms neural-network stack: how to build a NeuralNet, choose layers or optimizers, debug training phases and shapes, or adapt the repo's MLP/CNN/RNN/LSTM/DQN examples into shorter checks. The implementation is educational and CPU-only, with no external training service or model hub dependency.
Route elsewhere
- Tabular supervised estimators, SVM kernels, ensembles, KNN, Naive Bayes, and factorization machines belong in
../classical-estimators/SKILL.md. - KMeans, Gaussian mixtures, PCA, t-SNE, RBM, and demo dataset loaders belong in
../unsupervised-and-reduction/SKILL.md. - Cross-cutting install, provenance, and route selection remain in the root skill.
Start here
-
Confirm the package imports the neural stack you need:
from mla.neuralnet import NeuralNet from mla.neuralnet.layers import Dense, Activation, Dropout from mla.neuralnet.optimizers import Adam -
Choose the architecture family:
- Simple dense model:
Dense+Activation. - CNN:
Convolution,MaxPooling,Flatten,Dense. - Sequence model:
RNNorLSTM, optionally followed byTimeDistributedDenseorTimeStepSlicer. - Reinforcement learning wrapper:
mla.rl.dqn.DQNwith a user-provided neural model factory.
- Simple dense model:
-
Use explicit one-hot labels for
categorical_crossentropy, and remember thatNeuralNetuses a separateoptimizer.setup(self)step whenfitstarts. -
Run
scripts/run_neural_smoke.py --workflow allfor a short no-display check.
Primary workflows
Build a dense network
NeuralNet takes a list of layers plus an optimizer and a loss name. The container sets up layers, performs forward/backward passes, and delegates parameter updates to the optimizer.
from mla.neuralnet import NeuralNet
from mla.neuralnet.layers import Dense, Activation
from mla.neuralnet.optimizers import Adam
model = NeuralNet(
layers=[Dense(16), Activation("relu"), Dense(1)],
optimizer=Adam(),
loss="mse",
batch_size=32,
max_epochs=5,
metric="mse",
)
Convolutional workflow
Use Convolution, MaxPooling, Flatten, and Dense for the repo's MNIST-style example. The ConvNet expects image tensors shaped like (n_samples, n_channels, height, width).
Recurrent workflow
Use RNN or LSTM for sequence problems. The classes accept return_sequences=True by default, which is helpful for per-time-step outputs. TimeDistributedDense applies a dense layer to each time step.
DQN wiring
DQN is a lightweight training loop that asks the user to supply a model factory. It is designed around legacy Gym-style reset()/step() interactions and should be treated as an integration recipe rather than a production RL stack.
Bundled references and helpers
- Read
references/api-reference.mdfor exact constructor signatures and output/shape contracts. - Read
references/workflows.mdfor dense/CNN/RNN/DQN recipes and validation advice. - Read
references/neural-workflows.mdfor longer CNN and sequence reference workflows. - Read
references/rl-dqn.mdbefore touching CartPole or other Gym environments. - Read
references/troubleshooting.mdwhen training stalls, shapes break, or Gym/NumPy compatibility drifts. - Run
scripts/run_neural_smoke.py --workflow mlpor--workflow allfor a small installed-package check.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).