Skip to content

Commit

Permalink
use experimental filesystem:
Browse files Browse the repository at this point in the history
  • Loading branch information
baijumeswani committed May 3, 2024
1 parent 42bd715 commit ba3054d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct RootObject_Element : JSON::Element {
JSON::Element& t_;
};

void ParseConfig(const std::filesystem::path& filename, Config& config) {
void ParseConfig(const std::experimental::filesystem::path& filename, Config& config) {
std::ifstream file(filename, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
throw std::runtime_error("Error opening " + filename.string());
Expand All @@ -421,7 +421,7 @@ void ParseConfig(const std::filesystem::path& filename, Config& config) {
}
}

Config::Config(const std::filesystem::path& path) : config_path{path} {
Config::Config(const std::experimental::filesystem::path& path) : config_path{path} {
ParseConfig(path / "genai_config.json", *this);

if (model.context_length == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Generators {

struct Config {
Config() = default;
Config(const std::filesystem::path& path);
Config(const std::experimental::filesystem::path& path);

std::filesystem::path config_path; // Path of the config directory
std::experimental::filesystem::path config_path; // Path of the config directory

using ProviderOption = std::pair<std::string, std::string>;
struct ProviderOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <assert.h>
#include <cmath>
#include <cstring>
#include <filesystem>
#include <experimental/filesystem>
#include <functional>
#include "span.h"
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void SetLogString(std::string_view name, std::string_view value) {
if (value.empty())
gp_logfile.reset();
else {
std::filesystem::path filename{value};
std::experimental::filesystem::path filename{value};
gp_logfile = std::make_unique<std::ofstream>(filename);
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void Model::CreateSessionOptions() {
}

if (options.enable_profiling.has_value()) {
std::filesystem::path profile_file_prefix{options.enable_profiling.value()};
std::experimental::filesystem::path profile_file_prefix{options.enable_profiling.value()};
ort_options.EnableProfiling(profile_file_prefix.c_str());
}

Expand Down
4 changes: 2 additions & 2 deletions src/tokenizer/c_api/tfmtok_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

#include <cstdarg>
#include <filesystem>
#include <experimental/filesystem>
#include <algorithm>

#include "tfmtok.h"
Expand Down Expand Up @@ -117,7 +117,7 @@ tfmError_t TFM_API_CALL TfmCreateTokenizer(TfmTokenizer** tokenizer,
return kTfmErrorInvalidArgument;
}

if (!std::filesystem::is_directory(tokenizer_path)) {
if (!std::experimental::filesystem::is_directory(tokenizer_path)) {
last_error_message = std::string("Cannot find the directory of ") + tokenizer_path;
return kTfmErrorInvalidArgument;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tokenizer/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <fstream>
#include <streambuf>
#include <filesystem>
#include <experimental/filesystem>

#include "config.h"

Expand Down Expand Up @@ -68,8 +68,8 @@ TfmStatus TokenConfig::LoadJson(const std::string& json_path) {
simdjson::dom::parser parser;
simdjson::dom::element root;

if (!std::filesystem::exists(
std::filesystem::path(json_path).lexically_normal())) {
if (!std::experimental::filesystem::exists(
std::experimental::filesystem::path(json_path))) {
return {kTfmErrorInvalidFile, std::string(json_path) + " not found"};
}
std::string json_text = PatchJsonText(json_path);
Expand Down
7 changes: 4 additions & 3 deletions src/tokenizer/tokenizer.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "token_bpe.h"
#include "token_rwkv.h"

#include <filesystem>
#include <experimental/filesystem>
#include <memory>

namespace tfm {
Expand Down Expand Up @@ -30,7 +30,7 @@ TfmStatus CreateBPETokenizer(const std::string& tokenizer_path,
if (type.empty()) {
if (BPETokenizer::IsSupportedModel(GetModelName(token_cfg->tokenizer_class_))) {
type = "BPE";
} else if (std::filesystem::exists(tokenizer_path + "/tokenizer.model")) {
} else if (std::experimental::filesystem::exists(tokenizer_path + "/tokenizer.model")) {
// if 'tokenizer.model exists in the tokenizer_path, then it is a sentencepiece model
type = "SPM";
} else {
Expand All @@ -42,7 +42,8 @@ TfmStatus CreateBPETokenizer(const std::string& tokenizer_path,
token_ptr = std::make_unique<BPETokenizer>();
} /* else if (type == "SPM") {
token_ptr = std::make_unique<SpmTokenizer>();
} */ else {
} */
else {
status = TfmStatus(kTfmErrorInvalidArgument, "Unknown tokenizer_type, (BPE, SPM, RKWV) are supported.");
}

Expand Down

0 comments on commit ba3054d

Please sign in to comment.