Skip to content

Conversation

@ZoroZhao
Copy link
Collaborator

Use torch.nn.Parameter subclass to proxy the model parameter and trace the changes. It is compatible with the torch library.

@Essoz Essoz requested a review from Copilot September 20, 2025 18:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new ProxyParameter subclass of torch.nn.Parameter to enable parameter tracing that is compatible with the PyTorch library. The implementation provides an alternative to the existing proxy wrapper approach by leveraging PyTorch's subclassing mechanism.

Key changes:

  • Creates a ProxyParameter class that extends torch.nn.Parameter with tracing capabilities
  • Adds support for a new "proxyparameter" model tracker style alongside existing "proxy" and "sampler" modes
  • Updates observer and tracer components to handle ProxyParameter instances

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
traincheck/proxy_wrapper/subclass.py New file implementing ProxyParameter class and proxy_parameter function for parameter tracing
traincheck/proxy_wrapper/proxy_observer.py Updates observer to handle ProxyParameter instances alongside existing Proxy objects
traincheck/proxy_wrapper/proxy_config.py Adds proxy_attribute list for filtering ProxyParameter-specific attributes
traincheck/proxy_wrapper/proxy_basics.py Adds is_proxyparamtetr function to detect ProxyParameter instances
traincheck/instrumentor/tracer.py Updates tracer to recognize and handle ProxyParameter objects in function arguments
traincheck/instrumentor/source_file.py Adds "proxyparameter" mode support to model assignment instrumentation
traincheck/instrumentor/dumper.py Filters out proxy-specific attributes when dumping ProxyParameter objects
traincheck/collect_trace.py Adds "proxyparameter" as a valid choice for model tracker style

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +111 to +114

if from_iter:
phase = "iter"
# if the object is generated from getattr, then do not dump it
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic flow is incorrect. If from_call is True on line 109, phase is set to "call", but then if from_iter is also True, it gets overwritten to "iter". The else clause on line 115 should be elif to properly handle the case where neither from_call nor from_iter is True.

Suggested change
if from_iter:
phase = "iter"
# if the object is generated from getattr, then do not dump it
elif from_iter:
phase = "iter"

Copilot uses AI. Check for mistakes.
)

else:
raise ValueError(f"Invalid mode: {mode}. Must be one of ['proxy', 'sampler']")
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message is outdated and doesn't include the new "proxyparameter" mode. Should be "Must be one of ['proxy', 'sampler', 'proxyparameter']".

Suggested change
raise ValueError(f"Invalid mode: {mode}. Must be one of ['proxy', 'sampler']")
raise ValueError(f"Invalid mode: {mode}. Must be one of ['proxy', 'sampler', 'proxyparameter']")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants