examples: the optimizer's momentum quantization template is never freed

Open Beginner friendly
#549 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
documentation

Research direction

Review the listed example files, including examples/kws_tcresnet8/train_c.c as the reference pattern, and check the CreateOptim calls for inline quantizationInitFloat() templates. Keep each template in a local and free it after optimizer creation; run the examples' existing checks if available. Done when all affected examples and the fine-tune example free their templates after creation.

Written by the indexing model from the issue text.

Description

Problem

sgdMCreateOptim / adamWCreateOptim take a momentum quantization template that stays caller-owned (SgdApi.h): the optimizer clones it with getQLike per state during creation and never references it again. Most examples pass quantizationInitFloat() inline, so the template is never freed:

  • examples/ecg_anomaly_ae/train_c.c
  • examples/kws_mfcc/train_c.c
  • examples/kws_raw/train_c.c, examples/kws_raw/trace_c.c
  • examples/mixed_width_mlp/train_c.c
  • examples/mnist_cnn/train_c.c
  • examples/mnist_mlp/train_c.c
  • the fine-tune example (train_c_finetune.c) also never frees its template

(grep for CreateOptim( followed by quantizationInitFloat(); the list may miss multi-line calls.)

Effect

One quantization_t plus its config per optimizer, held until process exit. No effect on training. It makes ODT_MEM_PROFILE heap numbers a few bytes high, and the examples teach a pattern that leaks when an optimizer is created repeatedly (e.g. per person in a fine-tuning loop).

Fix

Keep the template in a local, free it right after the create call (as examples/kws_tcresnet8/train_c.c does). Optionally: document in SgdApi.h / AdamWApi.h that the template may be freed as soon as the create call returns.

Dominant language
C
Stars
2
Forks
3
Avg merge
13h 6m
Merged PRs (30d)
9

Getting set up

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.

More from es-ude/OnDeviceTraining

All issues in es-ude/OnDeviceTraining

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.