PIXELBANKv9.1.0
Menu

Count Model Parameters

Problem Statement

Count the total number of trainable parameters in a neural network.

Background

Understanding model size is important for deployment and memory planning. Each layer's parameters include weights and biases, and the total determines the model's capacity and memory footprint.

Your Task

Write a function count_parameters(in_features, hidden_features, out_features) that builds a two-layer network (with ReLU) and returns a breakdown of its trainable parameters.

Output Format

Return a dictionary with keys: "total_params" (int), "layer1_params" (int), "layer2_params" (int).

Example:

Input:
in_features=10, hidden_features=20, out_features=5
Output:
{'total_params': 325, 'layer1_params': 220, 'layer2_params': 105}
Reasoning:

Layer1: 1020+20=220, Layer2: 205+5=105, Total: 325

Constraints:

  • Linear layer params = in_features * out_features + out_features (bias)
  • Use param.numel() to count elements
πŸ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.