-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #778 from NVIDIA/torchtrtc_cli_cleanup
Refactor the CLI
- Loading branch information
Showing
11 changed files
with
599 additions
and
428 deletions.
There are no files selected for viewing
This file contains 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 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 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 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" | ||
|
||
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 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 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.