Skip to content

Add reference tag to allow getting a varaible by reference#3025

Closed
vladoovtcharov wants to merge 1 commit into
facebookresearch:mainfrom
vladoovtcharov:features/references
Closed

Add reference tag to allow getting a varaible by reference#3025
vladoovtcharov wants to merge 1 commit into
facebookresearch:mainfrom
vladoovtcharov:features/references

Conversation

@vladoovtcharov

Copy link
Copy Markdown

Motivation

Adds the ability to reference a variable without making a copy, similar to that proposed in #1393

Instead of singleton: true being added to the object, instead anywhere that wants to be instantiated as a reference to that variable can use the syntax:
foo: bar: _target_: "myclass" x: 4.0 reference_variable: _reference_: "foo.bar"
Then reference variable and foo.bar will refer to the same object after instantiate.

By registering a custom resolver the syntax ends up looking even nicer:

foo: bar: _target_: "myclass" x: 4.0 reference_variable: ${ref:foo.bar}

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Add test cases, especially for almost circular cases, e.g.
`
foo:
a: ${ref:bar.y}
b:
target: "ClassA"

bar:
x: ${ref:foo.b}
y:
target: "ClassB"
`
Also a bit worried about performance/memory usage with the proposed implementation but not sure about the best way to test that.

Related Issues and PRs

A different approach to PR#3103 but solves similar problem

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 7, 2025
@omry omry added the triage label May 16, 2026
@omry

omry commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the PR. This is an interesting idea, and the ref syntax may be a useful direction for the broader shared-object / instantiate identity problem.

I am going to close this PR for now because this API has not had maintainer feedback or buy-in yet. Beyond the missing tests and news fragment, there are also fundamental design questions still open, including initialization order, how references interact with normal OmegaConf interpolation, and cycle detection / error semantics.

Please continue the design discussion on #1393 before opening a new implementation PR. This will not make it into the upcoming 1.4 release.

@omry omry removed the triage label Jun 8, 2026
@omry omry closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants