Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Key Error #1194

Open
3 tasks
lordsoffallen opened this issue Sep 28, 2024 · 1 comment
Open
3 tasks

Duplicate Key Error #1194

lordsoffallen opened this issue Sep 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@lordsoffallen
Copy link

Describe the bug
Omega conf can't parse the valid yaml file with anchors defined. The following yaml throws duplicate key error for the section:

anthropic-cached: &anthropic-cache
    <<: *anthropic

When I replace that it works. That's a valid yaml format and key merging should happen

To Reproduce

_models:
  anthropic: &anthropic
    type: &LLM LargeModel
    backend: anthropic
    model: claude-3-5-sonnet-20240620
    credentials: anthropic-api-key
    model_params: &model-params
      temperature: !!float 0.5
  anthropic-cached: &anthropic-cache
    <<: *anthropic
    model_params:
      <<: *model-params
      extra_headers:
        anthropic-beta: prompt-caching-2024-07-31
  google: &google
    type: *LLM
    backend: google
    model: google/gemini-1.5-pro
    model_params: *model-params
    backend_kwargs:
      region: europe-west1
      project_id: 546565-n0
  llama-v3p1: &llama-v3p1
    type: *LLM
    backend: fireworks
    model: accounts/fireworks/models/llama-v3p1-70b-instruct
    credentials: fireworks-api-key
    model_params:
      <<: *model-params
      max_tokens: 16384

Expected behavior
I expect omegaconf to read the file without errors.

Additional context

  • OmegaConf version: 2.3.0
  • Python version: Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0]
  • Operating system: Ubuntu 22.04
@lordsoffallen lordsoffallen added the bug Something isn't working label Sep 28, 2024
@astrojuanlu
Copy link

I cannot reproduce:

from yaml import safe_load
from omegaconf import OmegaConf
from ruamel.yaml import YAML
yaml = YAML()
with open("conf.yaml") as fh:
    content = safe_load(fh)
    
content_oc = OmegaConf.load("conf.yaml")
with open("conf.yaml") as fh:
    content_ru = yaml.load(fh.read())
In [20]: OmegaConf.to_container(content_oc) == content
Out[20]: True

In [21]: OmegaConf.to_container(content_oc) == content_ru
Out[21]: True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants