ocannl icon indicating copy to clipboard operation
ocannl copied to clipboard

Refactor use_padding from a global shape inference setting to a field of the `Conv_input` constructor

Open lukstafi opened this issue 3 months ago • 2 comments

Good first step on the road to padding inference.

lukstafi avatar Sep 05 '25 09:09 lukstafi

@claude-opus please refactor use_padding from a global shape inference setting to a field of the Conv_input constructor. Localize the choices based on use_padding to now use the field of the corresponding Conv_input -- if there is no Conv_input to deconstruct in the context of a use-case, point out such places in your report.

lukstafi avatar Sep 18 '25 10:09 lukstafi

Claude finished @lukstafi's task —— View jobclaude/issue-386-20250918-1051Create PR ➔


Refactoring use_padding to Conv_input field ✅

Completed Tasks:

  • [x] Search for current use_padding implementation
  • [x] Locate Conv_input constructor definition
  • [x] Add use_padding field to Conv_input in both dim and proj types
  • [x] Update all Conv_input pattern matches in row.ml for both types
  • [x] Update all Conv_input constructor calls to include use_padding
  • [x] Build and verify changes compile successfully
  • [x] Commit and push changes

Summary of Changes

Successfully refactored use_padding from a global shape inference setting to a field of the Conv_input constructor. The changes include:

  1. Added use_padding: bool field to both:

    • The public dim type Conv_input constructor in row.ml and row.mli
    • The internal proj type Conv_input constructor in row.ml
  2. Updated all pattern matches and constructor calls to include the use_padding field across row.ml

  3. Kept the global use_padding variable for now because:

    • shape.ml creates Conv_input during einsum spec parsing
    • The use_padding value comes from the conv2d function parameter
    • Parsing happens independently of the conv2d call
    • Current workaround: nn_blocks.ml sets the global before einsum operations

Places without Conv_input context

The main location where we cannot directly use the Conv_input field is in shape.ml lines 420 and 1798 where Conv_input is constructed during einsum specification parsing. These locations currently use !Row.use_padding to get the value from the global reference.

The hack in nn_blocks.ml line 175 ([%oc Ocannl_tensor.Row.use_padding := use_padding]) is still necessary to pass the use_padding parameter to the shape inference system.

Next Steps

To fully eliminate the global variable would require one of:

  1. Extending einsum specification syntax to include padding information
  2. Adding a new API to configure padding at the operation level
  3. Refactoring the shape inference system to thread padding context through

For now, the refactoring successfully localizes use_padding to the Conv_input constructor, making the dependency explicit even though the global is still needed as a communication mechanism.


|

claude[bot] avatar Sep 18 '25 10:09 claude[bot]

This is fixed now.

lukstafi avatar Nov 30 '25 09:11 lukstafi