MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ParseShardingFromDevice

Function ParseShardingFromDevice

tensorflow/compiler/tf2xla/sharding_util.cc:52–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50} // namespace
51
52xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
53 const string& device_name, int num_cores_per_replica,
54 absl::optional<xla::OpSharding> explicit_sharding) {
55 if (device_name.empty()) {
56 return explicit_sharding;
57 }
58 DeviceNameUtils::ParsedName parsed_device;
59 if (!DeviceNameUtils::ParseFullName(device_name, &parsed_device)) {
60 return errors::InvalidArgument("Malformed assigned device '", device_name,
61 "'");
62 }
63
64 if (explicit_sharding.has_value()) {
65 return explicit_sharding;
66 } else if (!parsed_device.has_type || !parsed_device.has_id ||
67 !absl::StrContains(parsed_device.type,
68 kDeviceSuffixReplicatedCore)) {
69 return absl::optional<xla::OpSharding>();
70 } else {
71 const int core = parsed_device.id;
72 if (core < 0 || core >= num_cores_per_replica) {
73 return CoreOutOfRangeError(core, num_cores_per_replica);
74 }
75 return absl::optional<xla::OpSharding>(
76 xla::sharding_builder::AssignDevice(core));
77 }
78}
79
80xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
81 const NodeDef& node_def, int num_cores_per_replica) {

Callers 4

TESTFunction · 0.85
TESTFunction · 0.85
ComputeMethod · 0.85

Calls 9

InvalidArgumentFunction · 0.85
CoreOutOfRangeErrorFunction · 0.85
AssignDeviceFunction · 0.85
GetShardingFromNodeDefFunction · 0.85
StrContainsFunction · 0.50
TF_ASSIGN_OR_RETURNFunction · 0.50
emptyMethod · 0.45
has_valueMethod · 0.45
deviceMethod · 0.45

Tested by 2

TESTFunction · 0.68
TESTFunction · 0.68