-
Notifications
You must be signed in to change notification settings - Fork 364
Refactor the CLI #778
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
Merged
Merged
Refactor the CLI #778
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10957eb
refactor(//cpp/bin/torchtrtc)!: Rename enabled precisions arugment to
narendasan 0745c5f
refactor(//cpp/bin/torchtrtc): Refactor the CLI to make it easier to
narendasan 03bafc5
refactor!(//cpp/bin/torchtrtc): Removing the max-batch-size argument
narendasan 5adad06
chore: Apply C++ linting
narendasan b663154
refactor(//cpp/bin/torchtrtc): Updating help docs for torchtrtc
narendasan a182c0e
refactor(//cpp/bin/torchtrtc): Address review comments
narendasan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "accuracy.h" | ||
|
||
#include "torch_tensorrt/logging.h" | ||
#include "torch_tensorrt/torch_tensorrt.h" | ||
|
||
namespace torchtrtc { | ||
namespace accuracy { | ||
|
||
bool check_rtol(const at::Tensor& diff, const std::vector<at::Tensor> inputs, float threshold) { | ||
double maxValue = 0.0; | ||
for (auto& tensor : inputs) { | ||
maxValue = fmax(tensor.abs().max().item<float>(), maxValue); | ||
} | ||
torchtrt::logging::log( | ||
torchtrt::logging::Level::kDEBUG, | ||
std::string("Max Difference: ") + std::to_string(diff.abs().max().item<float>())); | ||
torchtrt::logging::log( | ||
torchtrt::logging::Level::kDEBUG, std::string("Acceptable Threshold: ") + std::to_string(threshold)); | ||
return diff.abs().max().item<float>() <= threshold * maxValue; | ||
} | ||
|
||
bool almost_equal(const at::Tensor& a, const at::Tensor& b, float threshold) { | ||
return check_rtol(a - b, {a, b}, threshold); | ||
} | ||
|
||
} // namespace accuracy | ||
} // namespace torchtrtc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <vector> | ||
|
||
#include "torch/script.h" | ||
#include "torch/torch.h" | ||
narendasan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace torchtrtc { | ||
namespace accuracy { | ||
|
||
bool check_rtol(const at::Tensor& diff, const std::vector<at::Tensor> inputs, float threshold); | ||
bool almost_equal(const at::Tensor& a, const at::Tensor& b, float threshold); | ||
|
||
} // namespace accuracy | ||
} // namespace torchtrtc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "fileio.h" | ||
|
||
namespace torchtrtc { | ||
namespace fileio { | ||
|
||
std::string read_buf(std::string const& path) { | ||
std::string buf; | ||
std::ifstream stream(path.c_str(), std::ios::binary); | ||
|
||
if (stream) { | ||
stream >> std::noskipws; | ||
std::copy(std::istream_iterator<char>(stream), std::istream_iterator<char>(), std::back_inserter(buf)); | ||
} | ||
|
||
return buf; | ||
} | ||
|
||
std::string get_cwd() { | ||
char buff[FILENAME_MAX]; // create string buffer to hold path | ||
if (getcwd(buff, FILENAME_MAX)) { | ||
std::string current_working_dir(buff); | ||
return current_working_dir; | ||
} else { | ||
torchtrt::logging::log(torchtrt::logging::Level::kERROR, "Unable to get current directory"); | ||
exit(1); | ||
} | ||
} | ||
|
||
std::string real_path(std::string path) { | ||
auto abs_path = path; | ||
char real_path_c[PATH_MAX]; | ||
char* res = realpath(abs_path.c_str(), real_path_c); | ||
if (res) { | ||
return std::string(real_path_c); | ||
} else { | ||
torchtrt::logging::log(torchtrt::logging::Level::kERROR, std::string("Unable to find file ") + abs_path); | ||
exit(1); | ||
} | ||
} | ||
|
||
std::string resolve_path(std::string path) { | ||
auto rpath = path; | ||
if (!(rpath.rfind("/", 0) == 0)) { | ||
rpath = get_cwd() + '/' + rpath; | ||
} | ||
return rpath; | ||
} | ||
|
||
} // namespace fileio | ||
} // namespace torchtrtc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
#ifdef __linux__ | ||
#include <linux/limits.h> | ||
#else | ||
#define PATH_MAX 260 | ||
#endif | ||
|
||
#if defined(_WIN32) | ||
#include <direct.h> | ||
#define getcwd _getcwd | ||
#define realpath(N, R) _fullpath((R), (N), PATH_MAX) | ||
#else | ||
#include <unistd.h> | ||
#endif | ||
|
||
#include "NvInfer.h" | ||
#include "third_party/args/args.hpp" | ||
#include "torch/script.h" | ||
#include "torch/torch.h" | ||
|
||
#include "torch_tensorrt/logging.h" | ||
#include "torch_tensorrt/ptq.h" | ||
#include "torch_tensorrt/torch_tensorrt.h" | ||
|
||
namespace torchtrtc { | ||
namespace fileio { | ||
|
||
std::string read_buf(std::string const& path); | ||
std::string get_cwd(); | ||
std::string real_path(std::string path); | ||
std::string resolve_path(std::string path); | ||
|
||
} // namespace fileio | ||
} // namespace torchtrtc |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.