Skip to content

Commit

Permalink
IFRT proxy: hacky flag for faster is_deleted().
Browse files Browse the repository at this point in the history
Setting the environment variable `IFRT_PROXY_ARRAY_IS_DELETED_HACK=enabled` in the OSS-compiled version of the IFRT proxy will make all `Array::IsDeleted()` calls to immediately return false.

This is not a generally safe optimization and trades off API correctness.

This acts as an interim solution for users while proper solutions are being debated or implemented.

PiperOrigin-RevId: 697450328
  • Loading branch information
Google-ML-Automation committed Nov 18, 2024
1 parent 58ea293 commit ed936d0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion xla/python/ifrt_proxy/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,11 @@ cc_library(
"global_flags_oss.cc",
],
visibility = ["//visibility:private"],
deps = ["@com_google_absl//absl/debugging:leak_check"],
deps = [
"@com_google_absl//absl/debugging:leak_check",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/strings",
],
)

cc_library(
Expand Down
3 changes: 3 additions & 0 deletions xla/python/ifrt_proxy/client/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ Future<> Array::Delete() {
}

bool Array::IsDeleted() const {
if (GetGlobalClientFlags()->array_is_deleted_hack) {
return false;
}
auto req = std::make_unique<IsArrayDeletedRequest>();
req->set_array_handle(handle_.handle);

Expand Down
6 changes: 5 additions & 1 deletion xla/python/ifrt_proxy/client/global_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ struct GlobalClientFlags {
// TODO(madthanu): Remove flag once there is confidence that the asynchronous
// codepath works well.
bool synchronous_host_buffer_store;

// TODO(b/375021159): Implement faster is_delete without needing a hack.
bool array_is_deleted_hack;
};

GlobalClientFlags* GetGlobalClientFlags();

inline std::ostream& operator<<(std::ostream& os, GlobalClientFlags flags) {
return os << "xla::ifrt::proxy::GlobalClientFlags{"
<< "synchronous_host_buffer_store="
<< flags.synchronous_host_buffer_store << "}";
<< flags.synchronous_host_buffer_store << ","
<< "array_is_deleted_hack=" << flags.array_is_deleted_hack << "}";
}

} // namespace proxy
Expand Down
21 changes: 21 additions & 0 deletions xla/python/ifrt_proxy/client/global_flags_oss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,37 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include <cstdlib>
#include <string>

#include "absl/debugging/leak_check.h"
#include "absl/log/check.h"
#include "absl/strings/numbers.h"
#include "xla/python/ifrt_proxy/client/global_flags.h"

namespace xla {
namespace ifrt {
namespace proxy {

namespace {

bool GetBoolFromEnv(const char* key) {
if (const char* valptr = std::getenv(key)) {
std::string val(valptr);
bool result;
QCHECK(absl::SimpleAtob(val, &result)) << " " << key << ": '" << val << "'";
return result;
}
return false;
}

} // namespace

static GlobalClientFlags DefaultGlobalClientFlags() {
GlobalClientFlags result;
result.synchronous_host_buffer_store = false;
result.array_is_deleted_hack =
GetBoolFromEnv("IFRT_PROXY_ARRAY_IS_DELETED_HACK");
return result;
};

Expand Down

0 comments on commit ed936d0

Please sign in to comment.