Пример #1
0
        internal static DistributionConfiguration DeserializeDistributionConfiguration(JsonElement element)
        {
            if (element.TryGetProperty("distributionType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Mpi": return(Mpi.DeserializeMpi(element));

                case "PyTorch": return(PyTorch.DeserializePyTorch(element));

                case "TensorFlow": return(TensorFlow.DeserializeTensorFlow(element));
                }
            }
            DistributionType distributionType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("distributionType"))
                {
                    distributionType = new DistributionType(property.Value.GetString());
                    continue;
                }
            }
            return(new DistributionConfiguration(distributionType));
        }
Пример #2
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("distributionType");
     writer.WriteStringValue(DistributionType.ToString());
     writer.WriteEndObject();
 }
Пример #3
0
        internal static PyTorch DeserializePyTorch(JsonElement element)
        {
            Optional <int?>  processCountPerInstance = default;
            DistributionType distributionType        = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("processCountPerInstance"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        processCountPerInstance = null;
                        continue;
                    }
                    processCountPerInstance = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("distributionType"))
                {
                    distributionType = new DistributionType(property.Value.GetString());
                    continue;
                }
            }
            return(new PyTorch(distributionType, Optional.ToNullable(processCountPerInstance)));
        }
Пример #4
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(ProcessCountPerInstance))
     {
         if (ProcessCountPerInstance != null)
         {
             writer.WritePropertyName("processCountPerInstance");
             writer.WriteNumberValue(ProcessCountPerInstance.Value);
         }
         else
         {
             writer.WriteNull("processCountPerInstance");
         }
     }
     writer.WritePropertyName("distributionType");
     writer.WriteStringValue(DistributionType.ToString());
     writer.WriteEndObject();
 }
Пример #5
0
        internal static TensorFlow DeserializeTensorFlow(JsonElement element)
        {
            Optional <int>   parameterServerCount = default;
            Optional <int?>  workerCount          = default;
            DistributionType distributionType     = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("parameterServerCount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    parameterServerCount = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("workerCount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        workerCount = null;
                        continue;
                    }
                    workerCount = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("distributionType"))
                {
                    distributionType = new DistributionType(property.Value.GetString());
                    continue;
                }
            }
            return(new TensorFlow(distributionType, Optional.ToNullable(parameterServerCount), Optional.ToNullable(workerCount)));
        }
Пример #6
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(ParameterServerCount))
     {
         writer.WritePropertyName("parameterServerCount");
         writer.WriteNumberValue(ParameterServerCount.Value);
     }
     if (Optional.IsDefined(WorkerCount))
     {
         if (WorkerCount != null)
         {
             writer.WritePropertyName("workerCount");
             writer.WriteNumberValue(WorkerCount.Value);
         }
         else
         {
             writer.WriteNull("workerCount");
         }
     }
     writer.WritePropertyName("distributionType");
     writer.WriteStringValue(DistributionType.ToString());
     writer.WriteEndObject();
 }