Skip to content

Conversation

@jas-ho
Copy link
Collaborator

@jas-ho jas-ho commented Jul 27, 2023

This is just, for now, just for discussion / knowledge sharing @gavento / @spirali

It shows a simple way of using hydra together with interlab.

engine=get_engine(cfg.judge),
initial_prompt=JUDGE_PROMPT,
)
storage = context.FileStorage(Path.cwd()) # Directory for storing contexts (structured logs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When using hydra, we should just write directly to cwd since hydra auto-changes into a unique output directory for every experimental run

return False


@hydra.main(config_path="conf", config_name="adversarial_prompting")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this tells hydra to look for a (yaml) config file at conf/adversarial_prompting.yaml

all the attributes specified in that config file become automatically available as CLI arguments

log.info(f"Git diff:\n{diff}")


class SymbolicLinkCallback(Callback):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is a slightly ugly (but working) hack to allow the current server implementation to work with the file structure generated by hydra

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hydra generates the following structure

results/<timestamp1>/<timestamped_context_file>
results/<timestamp2>/<another_timestamped_context_file>
...

what this hack does is to just create symlinks for each context file and folder in the parent directory as follows

results/<timestamped_context_file> -> results/<timestamp1>/<timestamped_context_file>
results/<another_timestamped_context_file> -> results/<timestamp2>/<another_timestamped_context_file>
...

If the server/storage was able to just see the files one level below we could avoid that


defaults:
- _self_
- override hydra/launcher: joblib # joblib launches runs in parallel; comment out if undesired
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

parallel execution using joblib has some trouble with pydantic and pickling (see cloudpipe/cloudpickle#408) . the issue appears only if pydantic classes are defined in the main script. ==> to avoid the problem define all pydantic classes in a separate module and import them in your main script

_log_git_sha()


def _log_git_sha():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would like to extract this method, as well as the log_exceptions method above so that it can be reused also without Hydra. Where should such logging utils go @spirali / @gavento?

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.

2 participants