MadWeightsOpen weights research. The Raw Uncut.
TUTORIAL ·

Cap an NVIDIA GPU's power, keep the cap after a restart, and judge the trade

Your NVIDIA cards will run under a power limit you chose, the limit will come back by itself after every restart, and you will have a log of temperature and power to judge it by. It works for any NVIDIA card that reports a power limit range, from a consumer card to a data-centre one.

Requirements: NVIDIA card that allows power limit changes (Kepler or newer) · Linux with systemd and root access · NVIDIA driver with nvidia-smi

Why cap at all: a lower limit means less heat, less fan noise and a smaller load on the power supply. Generation in a large language model is often limited by memory speed rather than by the GPU's arithmetic, so a moderate cap can cost less speed than the watts it saves. Measure whether that holds on your card and your model, and step 5 shows how.

Requirements

  • An NVIDIA card and driver with nvidia-smi
  • Root access to the machine
  • systemd, to keep the cap after a restart
  • A workload you can repeat exactly, for the measurement

Steps

1. Read the limits your card allows

Every card has a default limit and a range it accepts. Read them before choosing:

nvidia-smi --query-gpu=index,name,power.limit,power.default_limit,power.min_limit,power.max_limit,enforced.power.limit --format=csv

nvidia-smi -q -d POWER prints the same limits in a longer form. If your driver rejects a field name, nvidia-smi --help-query-gpu lists the names it accepts.

2. Set the cap

Turn on persistence mode so the driver keeps its state when no program is using the card, then set the limit in watts. Both need root.

nvidia-smi -pm 1
nvidia-smi -pl 200

Without -i, the limit applies to every card. To set one card, add -i with its index, or with its UUID or PCI bus ID, which NVIDIA recommends because they do not change. The value must lie between the minimum and maximum from step 1. NVIDIA's documentation states that persistence mode returns to Disabled after every restart, and you should expect the power limit to return to the default as well. That is why the next step exists.

3. Keep the cap after a restart

A oneshot systemd unit runs the two commands at every start. Save it as <unit-dir>/nvidia-powerlimit.service, with your own value:

[Unit]
Description=Cap NVIDIA GPU power limit
After=nvidia-persistenced.service
Wants=nvidia-persistenced.service

[Service]
Type=oneshot
ExecStart=/usr/bin/nvidia-smi -pm 1
ExecStart=/usr/bin/nvidia-smi -pl 200
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

A oneshot unit may carry several ExecStart= lines, which run in order, and RemainAfterExit=yes keeps it marked active after they finish. Check the path with command -v nvidia-smi. Enable it:

systemctl daemon-reload
systemctl enable --now nvidia-powerlimit

If an inference server starts at boot, add After=nvidia-powerlimit.service and Wants=nvidia-powerlimit.service to its unit, so it never runs a moment at the full default limit.

4. Log temperature and power

A cap is only useful if you can see what it does. This second unit writes one line per card every 30 seconds, using nvidia-smi's own loop option -l:

[Unit]
Description=Log GPU temperature, power, load and clock event reasons

[Service]
ExecStart=/bin/sh -c 'exec /usr/bin/nvidia-smi --query-gpu=timestamp,index,temperature.gpu,temperature.memory,utilization.gpu,power.draw,clocks.gr,clocks_event_reasons.active --format=csv,noheader -l 30 >> <log-dir>/gpu-log.csv'
Restart=always

[Install]
WantedBy=multi-user.target

Older drivers call the last field clocks_throttle_reasons.active. Use the name your driver lists in --help-query-gpu.

5. Measure tokens per second per watt

This is how to judge the trade.

  • Fix one prompt and one set of settings: same model file, same context, same sampling, same number of parallel requests, drafting on or off as you normally run it.
  • Set the first limit with nvidia-smi -pl, let the cards settle to a steady idle, then send the prompt and ask for a long reply of several hundred tokens or more.
  • While it generates, read power on every card once a second: nvidia-smi --query-gpu=index,power.draw --format=csv,noheader -l 1.
  • Take the generation speed from your server's reply or log. Average the power over the generating period only, summed across all cards that hold the model.
  • Divide tokens per second by that total. Repeat at least three times, then change the limit and repeat the whole set.

Speed varies between identical runs, sometimes by several percent (why), so treat small differences as no difference. Compare the realised speed too: a cap that wins per watt but makes replies too slow for you is not a win.

Check it worked

After a restart, run the query from step 1. power.limit and enforced.power.limit should match your value, not the default. Under sustained load, the log should record power close to the cap. A card can read slightly above the cap for a moment. The clock event reasons field should report the software power cap as active when the cap is holding the clock down; NVIDIA's documentation lists what each reason means. Values with no active reason under full load mean the cap is not binding at that load.

Common problems

  • The cap is gone after a restart: the unit is not enabled, or it ran before the driver was ready. Check systemctl status nvidia-powerlimit and order it after nvidia-persistenced.service.
  • One card runs hot under long jobs: watch the hottest card, not the average. nvidia-smi -q lists the card's own temperature limits. The card with the least airflow sets your cap.
  • Fans stay loud after capping: some servers cool third-party cards with a fixed airflow rule, so fan speed may not follow GPU power at all. That is a server setting, not a GPU one.
  • -pl is refused: the value is outside the card's range, the command was not run as root, or the card does not allow its limit to be changed.

Our recommendation

We'd cap any used data-centre card in a box it was not designed for, and start a step below the default, because the first watts you remove cost the least speed. On a card whose default is 250 W, such as the Tesla V100, we'd start at 200 W. Then we'd lower it in steps while watching the hottest card under the longest load you really run, and stop when the temperature has clear margin below the card's limit. We'd keep the logging unit running all the time: it costs almost nothing and answers most questions after the fact.

Further reading