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
[Runtime] Add config file for Device Config used in Runtime. #2978
Conversation
lib/Quantization/Serialization.cpp
Outdated
@@ -35,11 +35,33 @@ template <> struct MappingTraits<glow::NodeQuantizationInfo> { | |||
} | |||
}; | |||
|
|||
template <> struct BlockScalarTraits<glow::MultiLineStr> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that does not belong to quantization/serialization. Could you move that to a separate configs, lib/configs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add a test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very useful functionality! Thanks for working on this.
Questions:
- Do we really need this multi-line syntax? Or may be YAML has a nicer syntactic alternative for this?
- It could be that you do more work than needed and YAML parser can do more for you. @rdzhabarov had some experience with it for quantization. May be he can suggest a better way to use the YAML parser?
- Could you add a test with an example YAML file?
tools/loader/Loader.cpp
Outdated
/// Helper to get the BackendKind type from a backend's \p name. Need to be | ||
/// updated if a new backend comes. | ||
static BackendKind getBackendKindFromName(std::string &name) { | ||
if (name == "CPU") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM has llvm::StringMap
for it.
tools/loader/Loader.cpp
Outdated
} | ||
|
||
/// Helper to get the parameters in DeviceConfig from \p str. The \p str has | ||
/// multiply lines, and each line with this format : "str1" : "str2". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutiply->multiple.
Discussed with @rdzhabarov about the yaml file. So far, we haven't found a better way... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Thanks for doing it. Could you add a test to the expensive tests? It might require checking in an example config file but I think that would be useful to have anyway.
2a7eb21
to
2b39787
Compare
Added an unit test for checking yaml file format, and an expensive test for the whole flow. |
tests/runtime/configs.yaml
Outdated
@@ -0,0 +1,12 @@ | |||
--- | |||
- name: Device1 | |||
kindName: CPU |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit, if we are going to use a CPU maybe rename the parameters so it's clear they are test parameters, or put a comment that these parameters don't mean anything to the CPU backend.
std::string str; | ||
}; | ||
|
||
struct DeviceConfigHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in "Support.h" or some other header file that is related to device and device configurations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only used in Support.cpp for reading yaml file.
@@ -119,6 +119,26 @@ inline void report(llvm::StringRef str) { report(str.data()); } | |||
/// can be inspected under debugger. | |||
std::string legalizeName(llvm::StringRef name); | |||
|
|||
struct MultiLineStr { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -271,6 +280,43 @@ static Kinded::Kind getKindFromNodeName(llvm::StringRef nodeName) { | |||
GLOW_UNREACHABLE("Unknown node name."); | |||
} | |||
|
|||
/// Helper to get the BackendKind type from a backend's \p name. Need to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like details of the hardware leak into the loader. This means that every time we add a new hardware backend we would need to update this file. Is there a way to avoid it?
@gcatron was working on something simiar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a chat with @rdzhabarov last week related to this. When we move to dynamic backend registration there will be a string:backendKind map that can be used. I think this solution is a temporary one until we have that map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already essentially have this map via llvm::cl::opt<BackendKind> ExecutionBackend
here in the Loader. If we must have a map like this too, I think we should unify them somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have a follow up PR for this, since some tests command line maybe changed as well.
tools/loader/Loader.cpp
Outdated
for (unsigned int i = 0; i < numDevices; ++i) { | ||
auto config = llvm::make_unique<runtime::DeviceConfig>(ExecutionBackend); | ||
configs.push_back(std::move(config)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a lot of logic to a function that is already long. Is there a way to refactor things and make the code more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got this piece of code into a function.
@@ -18,6 +18,10 @@ | |||
#include "glow/Testing/StrCheck.h" | |||
#include "gtest/gtest.h" | |||
|
|||
#ifndef GLOW_DATA_PATH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required for the fbcode setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Got it. Thank you.
tools/loader/Loader.cpp
Outdated
std::istringstream f(str.c_str()); | ||
while (getline(f, s, '\n')) { | ||
size_t pos1, pos2, pos3, pos4; | ||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
7bb76de
to
b8ce02e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beicy has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
tools/loader/Loader.cpp
Outdated
/// configs from the file. Otherwise, create \p numDevices number of devices | ||
/// based on \p backendKind. | ||
static void generateDeviceConfigs( | ||
std::vector<std::unique_ptr<runtime::DeviceConfig>> &configs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can generateDeviceConfigs return the vector of configs? That way we don't have to pass in a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, once we have dynamic backend discovery we should be able to remove hw specific info from the loader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beicy has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary:
Enable Loader to get device configs from a config yaml file.
Now there are 2 ways in Loader to get the DeviceConfigs:
Documentation:
Test Plan:
The config file example is :
The command line:
./bin/text-translator -m "en2gr" -cpu -cpu-memory=500000 -load-device-configs="configs.yaml" <<< "I love music ."
[Optional Fixes #issue]
Please see a detailed explanation of how to fill out the fields in the relevant sections in PULL_REQUEST.md.