Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Getting keyerror using annotation in a class #801

Closed
JohnAllen opened this issue Mar 2, 2019 · 4 comments
Closed

Getting keyerror using annotation in a class #801

JohnAllen opened this issue Mar 2, 2019 · 4 comments
Assignees
Labels
Annotation bug Something isn't working user raised

Comments

@JohnAllen
Copy link

Short summary about the issue/question:

I'm getting this:

File "/home/xhaojing/.local/lib/python3.6/site-packages/nni/trial.py", line 53, in get_current_parameter
    return _params['parameters'][tag]
KeyError: 'Reward/failure_reward/choice

when I use an annotation in a class imported to my main training file.

This is the code that throws it:

class Reward:
    def __init__(self, data):
        self.Data = data
        """@nni.variable(nni.choice(-1, -0.5, -0.1, -0.01, -0.001, -0.0001), name=failure_reward)"""
        failure_reward = -.01
        self.failure_reward = failure_reward

**Brief what process you are following**: This is a local machine, **How to reproduce it**: Instantiate a class (that runs the code above) in a main training script like so:Reward = Reward(data)`

nni Environment:

  • nni version: 0.5.1
  • nni mode(local|pai|remote): local
  • OS: Ubuntu 18
  • python version: 3.6.7
  • is conda or virtualenv used?: NO
  • is running in docker?: NO
@JohnAllen
Copy link
Author

Figured it out. Some files were in a separate dir from main training file and NNI was looking for lib/some_annotated_var and not some_annotated_var. Moved files into same dir and everything worked.

I would call it a bug though that you have to have files in the same dir. Or what am I missing?

@Crysple
Copy link
Contributor

Crysple commented Mar 3, 2019

Hi @ @JohnAllen, thanks for reporting this.
It seems that the inspect library is running differently than expected. Originally we'd like to include it's path in it's key so there won't be two keys with the same name. I'll fix this soon. As you say, currently you can move them into the same dir as a temporary measure

@chicm-ms
Copy link
Contributor

chicm-ms commented Mar 8, 2019

Fixed.

@chicm-ms chicm-ms closed this as completed Mar 8, 2019
@scarlett2018 scarlett2018 added the bug Something isn't working label Mar 27, 2019
@scarlett2018 scarlett2018 added this to the March 2019 Release v0.6 milestone Mar 27, 2019
@scarlett2018 scarlett2018 reopened this Mar 27, 2019
@scarlett2018
Copy link
Member

@Crysple @yds05 - confirm to have this in v0.6.

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

No branches or pull requests

4 participants