예제 #1
0
파일: Program.cs 프로젝트: nerai/Zysl
 private static void TestCached()
 {
     var backing = new GenericBackedCache (
         new DictionaryStore (),
         new FileStore ("./myBackingStore"));
     var store = new KVStore<string, DateTime> (backing);
 }
예제 #2
0
        internal static void InitializeKVStore(KVStore kvstore, List <NDArrayList> param_arrays, NDArrayDict arg_params,
                                               string[] param_names, bool update_on_kvstore)
        {
            for (int i = 0; i < param_arrays.Count; i++)
            {
                if (param_arrays[i].Length == 0)
                {
                    continue;
                }

                if (param_arrays[i][0] == null)
                {
                    continue;
                }

                var name          = param_names[i];
                var param_on_devs = param_arrays[i];
                kvstore.Init(name, arg_params[name]);

                if (update_on_kvstore)
                {
                    kvstore.Pull(name, param_on_devs, -i);
                }
            }
        }
예제 #3
0
        public void SetUp()
        {
            global::Cassandra.Cluster cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
            Session session = cluster.Connect();

            KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new KeyValueStorage.Cassandra.CassandraStoreProvider(session)));
        }
예제 #4
0
        /// <summary>
        /// Constructs a new CognitoAWSCredentials instance, which will use the
        /// specified Amazon Cognito identity pool to make a requests to the
        /// AWS Security Token Service (STS) to request short lived session credentials.
        /// </summary>
        /// <param name="accountId">The AWS accountId for the account with Amazon Cognito</param>
        /// <param name="identityPoolId">The Amazon Cogntio identity pool to use</param>
        /// <param name="unAuthRoleArn">The ARN of the IAM Role that will be assumed when unauthenticated</param>
        /// <param name="authRoleArn">The ARN of the IAM Role that will be assumed when authenticated</param>
        /// <param name="region">Region to use when accessing Amazon Cognito and AWS Security Token Service.</param>
        public CachingCognitoAWSCredentials(
            string accountId, string identityPoolId,
            string unAuthRoleArn, string authRoleArn,
            RegionEndpoint region)
            : this(
                unAuthRoleArn, authRoleArn,
                new AmazonCognitoIdentityProvider(accountId, identityPoolId, new AnonymousAWSCredentials(), region),
                new AmazonSecurityTokenServiceClient(new AnonymousAWSCredentials(), region))
        {
            if (string.IsNullOrEmpty(accountId))
            {
                throw new ArgumentNullException("accountId cannot be null");
            }
            if (string.IsNullOrEmpty(identityPoolId))
            {
                throw new ArgumentNullException("identityPoolId cannot be null");
            }
            if (string.IsNullOrEmpty(unAuthRoleArn) && string.IsNullOrEmpty(authRoleArn))
            {
                throw new ArgumentNullException("Both unAuthRoleArn and authRoleArn cannot be null");
            }
#if UNITY_WEBPLAYER
            _persistentStore = new InMemoryKVStore();
#else
            _persistentStore = new SQLiteKVStore();
#endif

            string IP = _persistentStore.Get(IP_KEY);

            if (!string.IsNullOrEmpty(IP) && 0 == IP.CompareTo(identityPoolId))
            {
                IdentityProvider.UpdateIdentity(_persistentStore.Get(ID_KEY));

                AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CachingCognitoAWSCredentials", "Loaded Cached IdentityID from LocalStorage");
                loadCachedCredentials();
            }
            else if (!string.IsNullOrEmpty(IP))
            {
                // identity pool id is different from whats caching
                Clear();
            }

            IdentityProvider.IdentityChangedEvent += delegate(object sender, IdentityChangedArgs e)
            {
                if (!string.IsNullOrEmpty(e.OldIdentityId))
                {
                    this.Clear();
                }
                if (string.IsNullOrEmpty(_persistentStore.Get(IP_KEY)))
                {
                    // identity pool id is not cached
                    _persistentStore.Put(IP_KEY, this.IdentityProvider.IdentityPoolId);
                }
                // caching identity whenever new identity is found
                _persistentStore.Put(ID_KEY, e.NewIdentityId);
                AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CachingCognitoAWSCredentials", "Saved identityID to LocalStorage");
            };
        }
        public void TestPutGet()
        {
            var key   = "k1";
            var value = "v1";

            var name  = "test";
            var store = KVStore.Open(name);

            store.Put(key, value);

            Assert.AreEqual(name, store.Name);
            Assert.AreEqual(value, store.Get(key));
        }
예제 #6
0
        public void BorrowOptimizer(Module shared_module)
        {
            if (!shared_module.OptimizerInitialized)
            {
                throw new Exception("Shared moidule optimizer not initialized");
            }

            _optimizer           = shared_module._optimizer;
            _kvstore             = shared_module._kvstore;
            _update_on_kvstore   = shared_module._update_on_kvstore;
            _updater             = shared_module._updater;
            OptimizerInitialized = true;
        }
예제 #7
0
        public void TestPutGet()
        {
            string key   = "k1";
            string value = "v1";

            string  name  = "test";
            KVStore store = KVStore.Open(name);

            store.Put(key, value);

            Assert.AreEqual(name, store.Name);
            Assert.AreEqual(value, store.get(key));
        }
예제 #8
0
        internal static void UpdateParams(List <NDArrayList> param_arrays, List <NDArrayList> grad_arrays,
                                          Updater updater, int num_device, KVStore kvstore, string[] param_names)
        {
            Dictionary <int, List <(int, NDArray, NDArray)> > updates = new Dictionary <int, List <(int, NDArray, NDArray)> >();

            for (int i = 0; i < num_device; i++)
            {
                updates.Add(i, new List <(int, NDArray, NDArray)>());
            }

            for (int i = 0; i < param_arrays.Count; i++)
            {
                var arg_list  = param_arrays[i];
                var grad_list = grad_arrays[i];

                if (grad_list.Length == 0)
                {
                    continue;
                }

                if (grad_list[0] == null)
                {
                    continue;
                }

                int index = i;
                if (kvstore != null)
                {
                    string name = param_names[index];
                    kvstore.Push(name, grad_list, -index);
                    kvstore.Pull(name, arg_list, -index);
                }

                for (int j = 0; j < arg_list.Length; j++)
                {
                    var w = arg_list[j];
                    var g = grad_list[j];
                    updates[i].Add((index * num_device + j, w, g));
                }

                foreach (var dev_updates in updates.Values)
                {
                    foreach (var item in dev_updates)
                    {
                        var(idx, w, g) = item;
                        updater.Call(idx, w, g);
                    }
                }
            }
        }
예제 #9
0
        public void SetUp()
        {
            var config = new global::Couchbase.Configuration.CouchbaseClientConfiguration()
            {
                Bucket   = "default",
                Password = "******"
            };

            config.Urls.Add(new Uri("http://127.0.0.1:8091/pools"));

            var client  = new global::Couchbase.CouchbaseClient(config);
            var cluster = new global::Couchbase.Management.CouchbaseCluster(config);
            var stats   = client.Stats();

            KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new Couchbase.CouchbaseStoreProvider(client, cluster, config.Bucket)));
        }
예제 #10
0
        internal static (KVStore, bool) CreateKVStore(KVStore kvstore, int num_device, NDArrayDict arg_params)
        {
            var update_on_kvstore = true;

            if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("MXNET_UPDATE_ON_KVSTORE")))
            {
                update_on_kvstore = Convert.ToBoolean(Environment.GetEnvironmentVariable("MXNET_UPDATE_ON_KVSTORE"));
            }

            if (kvstore == null)
            {
                update_on_kvstore = false;
            }

            return(kvstore, update_on_kvstore);
        }
예제 #11
0
파일: Program.cs 프로젝트: nerai/Zysl
        private static void TestSimple()
        {
            // todo: in protobuf: empty lists are returned as null (known bug by design)

            var backing = new FileStore ("TestSimple");
            var store = new KVStore<string, TestItem> (backing);

            Action<TestItem> test = item => {
                store[item.Time.Ticks.ToString ()] = item;
                var read = store[item.Time.Ticks.ToString ()];
                Console.WriteLine (item);
                Console.WriteLine (read);
            };

            test (new TestItem (DateTime.Now, null));
            test (new TestItem (DateTime.Now, new string[0]));
            test (new TestItem (DateTime.Now, new string[] { "1", "2" }));
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.SubmissionTimePolicy"/> class.
        /// </summary>
        /// <param name="WaitInterval">Wait interval.</param>
        public SubmissionTimePolicy(long WaitInterval)
        {
            this.WaitInterval = WaitInterval;

            //retrieve the last submitted timestamp from the cache
            _persistStore = new PlayerPreferenceKVStore();

            String TimeStamp = _persistStore.Get(LAST_SUCCESSFUL_DELIVERY_TIME_STAMP_KEY);

            if (TimeStamp != null && TimeStamp.Length > 0)
            {
                this.LastSubmittedTime = long.Parse(TimeStamp);
            }
            else
            {
                this.LastSubmittedTime = 0;
            }
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.ClientContextConfig"/> class.
        /// </summary>
        /// <param name="appTitle">App title -  The title of your app. For example, My App.</param>
        /// <param name="appVersionName">App version name - The version of your app. For example, V2.0.</param>
        /// <param name="appVersionCode">App version code - The version code for your app. For example, 3.</param>
        /// <param name="appPackageName">App package name - The name of your package. For example, com.example.my_app.</param>
        /// <param name="appId">App identifier - AWS Mobile Analytics App ID corresponding to your App</param>
        public ClientContextConfig(string appTitle, string appVersionName, string appVersionCode, string appPackageName, string appId)
        {
            if (string.IsNullOrEmpty(appTitle))
            {
                throw new ArgumentNullException("appTitle");
            }

            if (string.IsNullOrEmpty(appVersionName))
            {
                throw new ArgumentNullException("appVersionName");
            }

            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException("appId");
            }

            if (string.IsNullOrEmpty(appPackageName))
            {
                throw new ArgumentNullException("appPackageName");
            }

            if (string.IsNullOrEmpty(appVersionCode))
            {
                throw new ArgumentNullException("appVersionCode");
            }

            this._appTitle       = appTitle;
            this._appVersionName = appVersionName;
            this._appVersionCode = appVersionCode;
            this._appPackageName = appPackageName;
            this._appId          = appId;

            _kvStore  = new PlayerPreferenceKVStore();
            _clientId = _kvStore.Get(APP_CLIENT_ID_KEY);
            if (string.IsNullOrEmpty(_clientId))
            {
                _clientId = Guid.NewGuid().ToString();
                _kvStore.Put(APP_CLIENT_ID_KEY, _clientId);
            }
        }
예제 #14
0
        internal static void UpdateParamsOnKVStoreNCCL(List <NDArrayList> param_arrays, List <NDArrayList> grad_arrays,
                                                       KVStore kvstore, string[] param_names)
        {
            List <int> valid_indices = new List <int>();
            int        i             = 0;

            grad_arrays.ForEach((x) => {
                valid_indices.Add(i);
                i++;
            });

            var valid_grad_arrays  = valid_indices.Select(x => (grad_arrays[x])).ToArray();
            var valid_param_arrays = valid_indices.Select(x => (param_arrays[x])).ToArray();
            var valid_param_names  = valid_indices.Select(x => (param_names[x])).ToArray();

            int size  = valid_grad_arrays.Length;
            int start = 0;
            int batch = 16;

            if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("MXNET_UPDATE_AGGREGATION_SIZE")))
            {
                batch = Convert.ToInt32(Environment.GetEnvironmentVariable("MXNET_UPDATE_AGGREGATION_SIZE"));
            }

            while (start < size)
            {
                int end              = start + batch < size ? start + batch : size;
                var name_batch_list  = valid_param_names.Skip(start).Take(end - start).ToArray();
                var grad_batch_list  = valid_grad_arrays.Skip(start).Take(end - start).ToArray();
                var param_batch_list = valid_grad_arrays.Skip(start).Take(end - start).ToArray();

                for (int kvi = 0; kvi < name_batch_list.Length; kvi++)
                {
                    kvstore.Push(valid_param_names[kvi], valid_grad_arrays[kvi], -start);
                    kvstore.Pull(valid_param_names[kvi], param_batch_list[kvi], -start);
                }

                start = end;
            }
        }
예제 #15
0
        /// <summary>
        /// Constructs a new CognitoAWSCredentials instance, which will use the
        /// specified Amazon Cognito identity pool to make a requests to the
        /// AWS Security Token Service (STS) to request short lived session credentials.
        /// </summary>
        /// <param name="accountId">The AWS accountId for the account with Amazon Cognito</param>
        /// <param name="identityPoolId">The Amazon Cogntio identity pool to use</param>
        /// <param name="unAuthRoleArn">The ARN of the IAM Role that will be assumed when unauthenticated</param>
        /// <param name="authRoleArn">The ARN of the IAM Role that will be assumed when authenticated</param>
        /// <param name="cibClient">Preconfigured Cognito Identity client to make requests with</param>
        /// <param name="stsClient">Preconfigured STS client to make requests with</param>
        public CognitoAWSCredentials(string unAuthRoleArn, string authRoleArn,
                                     AbstractCognitoIdentityProvider idClient, IAmazonSecurityTokenService stsClient)
        {
            if (idClient == null)
            {
                throw new ArgumentNullException("idClient");
            }

            UnAuthRoleArn    = unAuthRoleArn;
            AuthRoleArn      = authRoleArn;
            IdentityProvider = idClient;
            sts = stsClient;

                        #if UNITY_WEBPLAYER
            _persistentStore = new InMemoryKVStore();
                        #else
            _persistentStore = new SQLiteKVStore();
                        #endif

            //Load cached credentials
            string cachedIdentity = _persistentStore.Get(namespacedKey(ID_KEY));
            if (string.IsNullOrEmpty(cachedIdentity))
            {
                //Try to recover unamespaced identities stored by old versions of the SDK
                cachedIdentity = _persistentStore.Get(ID_KEY);
            }
            if (!string.IsNullOrEmpty(cachedIdentity))
            {
                IdentityProvider.UpdateIdentity(cachedIdentity);
                loadCachedCredentials();
            }

            //Register Identity Changed Listener to update the cache
            IdentityProvider.IdentityChangedEvent += delegate(object sender, IdentityChangedArgs e)
            {
                saveCredentials();
                AmazonLogging.Log(AmazonLogging.AmazonLoggingLevel.Verbose, "CognitoAWSCredentials", "Saved identityID to LocalStorage");
            };
        }
예제 #16
0
        internal static void UpdateParamsOnKVStore(List <NDArrayList> param_arrays, List <NDArrayList> grad_arrays,
                                                   KVStore kvstore, string[] param_names)
        {
            for (int index = 0; index < param_arrays.Count; index++)
            {
                var arg_list  = param_arrays[index];
                var grad_list = grad_arrays[index];

                if (grad_list.Length == 0)
                {
                    continue;
                }

                if (grad_list[0] == null)
                {
                    continue;
                }

                string name = param_names[index];
                kvstore.Push(name, grad_list, -index);
                kvstore.Pull(name, arg_list, -index);
            }
        }
예제 #17
0
        public Trainer(ParameterDict @params, Optimizer optimizer, string kvstore = "device",
                       Dictionary <string, object> compression_params             = null, bool?update_on_kvstore = null)
        {
            var paramValues = @params.Values();

            _params = new List <Parameter>();
            var keys = @params.Keys();

            for (var i = 0; i < keys.Length; i++)
            {
                var param = @params[keys[i]];
                _param2idx[keys[i]] = i;
                _params.Add(param);
                param.SetTrainer(this);
                if (param.Stype != StorageStype.Default)
                {
                    _contains_sparse_weight = true;
                }

                if (param.Grad_Stype != StorageStype.Default)
                {
                    _contains_sparse_grad = true;
                }
            }

            _compression_params = compression_params;
            _contexts           = CheckContexts();
            InitOptimizer(optimizer);
            _scale          = optimizer.RescaleGrad;
            _kvstore_params = new Dictionary <string, object>();
            _kvstore_params.Add("kvstore", kvstore);
            _kvstore_params.Add("update_on_kvstore", update_on_kvstore);
            _kvstore           = null;
            _update_on_kvstore = null;
            _params_to_init    = new List <Parameter>();
            ResetKVstore();
        }
예제 #18
0
        internal static (KVStore, bool) CreateKVStore(string kvstore, int num_device, NDArrayDict arg_params)
        {
            KVStore kV = null;
            var     update_on_kvstore = true;

            if (num_device == 1 && !kvstore.Contains("dist"))
            {
                kV = null;
            }
            else
            {
                kV = KVStoreBase.Create(kvstore);
                if (kvstore == "local")
                {
                    var max_size = arg_params.Values.Select(x => x.Shape.Size).ToList().Max();
                    if (max_size > 1024 * 1024 * 16)
                    {
                        update_on_kvstore = false;
                    }
                }
            }

            return(kV, update_on_kvstore);
        }
예제 #19
0
파일: Program.cs 프로젝트: nerai/Zysl
 private static void TestAutoCtor()
 {
     var kvs = new KVStore<DateTime, TestItem> ();
     kvs[DateTime.Now] = new TestItem (DateTime.Now, new string[] { "foo" });
 }
예제 #20
0
 public void SetUp()
 {
     KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new AzureTableStoreProvider(CloudStorageAccount.DevelopmentStorageAccount)));
 }
예제 #21
0
        internal static (KVStore, bool) CreateSparseKVStore(KVStore kvstore)
        {
            var update_on_kvstore = true;

            return(kvstore, update_on_kvstore);
        }
예제 #22
0
        internal static void TrainMultiDevice(Symbol symbol, Context[] ctx, string[] arg_names, string[] param_names, string[] aux_names, NDArrayDict arg_params, NDArrayDict aux_params, int begin_epoch, int end_epoch, int?epoch_size, Optimizer optimizer, KVStore kvstore, bool update_on_kvstore, DataIter train_data, DataIter eval_data = null, EvalMetric eval_metric = null, IEpochEndCallback epoch_end_callback = null, IBatchEndCallback batch_end_callback = null, int[] work_load_list = null, Monitor monitor = null, IEvalEndCallback eval_end_callback = null, IEvalBatchEndCallback eval_batch_end_callback = null, Func <int, Symbol> sym_gen = null)
        {
            var executor_manager = new DataParallelExecutorManager(symbol: symbol,
                                                                   ctx: ctx,
                                                                   train_data: train_data,
                                                                   arg_names: arg_names,
                                                                   param_names: param_names,
                                                                   aux_names: aux_names,
                                                                   work_load_list: work_load_list,
                                                                   sym_gen: sym_gen);

            if (monitor != null)
            {
                executor_manager.InstallMonitor(monitor);
            }

            executor_manager.SetParams(arg_params, aux_params);
            Updater updater = null;

            if (!update_on_kvstore)
            {
                updater = Optimizer.GetUpdater(optimizer);
            }
            else
            {
                kvstore.SetOptimizer(optimizer);
            }

            if (kvstore != null)
            {
                InitializeKVStore(kvstore: kvstore,
                                  param_arrays: new List <NDArrayList>()
                {
                    executor_manager.ParamArrays
                },
                                  arg_params: arg_params,
                                  param_names: executor_manager.param_names,
                                  update_on_kvstore: update_on_kvstore);
            }

            train_data.Reset();
            for (int epoch = begin_epoch; epoch < end_epoch; epoch++)
            {
                var tic = DateTime.Now;
                eval_metric.Reset();
                int nbatch = 0;
                while (true)
                {
                    bool do_reset = true;
                    while (!train_data.End())
                    {
                        var data_batch = train_data.Next();
                        executor_manager.LoadDataBatch(data_batch);
                        if (monitor != null)
                        {
                            monitor.Tic();
                        }

                        executor_manager.Forward(true);
                        executor_manager.Backward();
                        if (update_on_kvstore)
                        {
                            if (kvstore.Type.Contains("nccl"))
                            {
                                UpdateParamsOnKVStoreNCCL(new List <NDArrayList>()
                                {
                                    executor_manager.ParamArrays
                                }, new List <NDArrayList>()
                                {
                                    executor_manager.GradArrays
                                }, kvstore, executor_manager.param_names);
                            }
                            else
                            {
                                UpdateParamsOnKVStore(new List <NDArrayList>()
                                {
                                    executor_manager.ParamArrays
                                }, new List <NDArrayList>()
                                {
                                    executor_manager.GradArrays
                                }, kvstore, executor_manager.param_names);
                            }
                        }
                        else
                        {
                            UpdateParams(new List <NDArrayList>()
                            {
                                executor_manager.ParamArrays
                            }, new List <NDArrayList>()
                            {
                                executor_manager.GradArrays
                            }, updater, ctx.Length, kvstore, executor_manager.param_names);
                        }

                        if (monitor != null)
                        {
                            monitor.TocPrint();
                        }

                        executor_manager.UpdateMetric(eval_metric, data_batch.Label);
                        nbatch++;
                        if (batch_end_callback != null)
                        {
                            MultipleCallbacks(batch_end_callback, epoch, nbatch, eval_metric);
                        }

                        if (epoch_size.HasValue && nbatch >= epoch_size.Value)
                        {
                            do_reset = false;
                            break;
                        }
                    }

                    if (do_reset)
                    {
                        Logger.Info($"Epoch[{epoch}] Resetting Data Iterator");
                        train_data.Reset();
                    }

                    if (epoch_size.HasValue)
                    {
                        if (nbatch >= epoch_size.Value)
                        {
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                var toc = DateTime.Now;
                Logger.Info($"Epoch[{epoch}] Time cost={(toc - tic).TotalSeconds}");

                if (epoch_end_callback != null || epoch + 1 == end_epoch)
                {
                    executor_manager.CopyTo(arg_params, aux_params);
                }

                MultipleCallbacks(epoch_end_callback, epoch, symbol, arg_params, aux_params);

                if (eval_data != null)
                {
                    eval_metric.Reset();
                    eval_data.Reset();
                    int total_num_batch = 0;
                    int i = 0;
                    while (!eval_data.End())
                    {
                        var eval_batch = eval_data.Next();
                        executor_manager.LoadDataBatch(eval_batch);
                        executor_manager.Forward();
                        executor_manager.UpdateMetric(eval_metric, eval_batch.Label);
                        if (eval_batch_end_callback != null)
                        {
                            MultipleCallbacks(eval_batch_end_callback, epoch, i, eval_metric);
                        }

                        total_num_batch++;
                    }

                    if (eval_end_callback != null)
                    {
                        MultipleCallbacks(eval_end_callback, epoch, eval_metric);
                    }
                }
            }
        }
예제 #23
0
 public void SetUp()
 {
     KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new KeyValueStorage.FSText.FSTextStoreProvider(@"C:\FSTextStore")));
 }
예제 #24
0
 public ApplicationSettings()
 {
     kvStore = new PlayerPreferenceKVStore();
 }
예제 #25
0
        public Module(Symbol symbol, string[] data_names = null, string[] label_names = null,
                      Context[] context    = null, int[] work_load_list = null, string[] fixed_param_names = null,
                      string[] state_names = null,
                      Dictionary <string, Context>[] group2ctxs = null, Dictionary <string, object> compression_params = null)
        {
            if (context == null)
            {
                context = new[] { Context.Cpu() }
            }
            ;

            if (work_load_list == null)
            {
                work_load_list = new int[context.Length];
                for (var i = 0; i < work_load_list.Length; i++)
                {
                    work_load_list[i] = 1;
                }
            }

            if (context.Length != work_load_list.Length)
            {
                throw new Exception("Context and WorkLoadList length are not equal");
            }

            _group2ctxs        = group2ctxs;
            _symbol            = symbol;
            _data_names        = data_names != null ? data_names : new string[0];
            _label_names       = label_names != null ? label_names : new string[0];
            _state_names       = state_names != null ? state_names : new string[0];
            _fixed_param_names = fixed_param_names != null ? fixed_param_names : new string[0];
            CheckInputNames(symbol, _data_names, "data", true);
            CheckInputNames(symbol, _label_names, "label", false);
            CheckInputNames(symbol, _state_names, "state", true);
            CheckInputNames(symbol, _fixed_param_names, "fixed_param", true);

            var arg_names   = symbol.ListArguments();
            var input_names = new List <string>();

            input_names.AddRange(_data_names);
            input_names.AddRange(_label_names);
            input_names.AddRange(_state_names);

            _param_names  = arg_names.Where(x => arg_names.Contains(x)).ToArray();
            _aux_names    = symbol.ListAuxiliaryStates().ToArray();
            OutputNames   = symbol.ListOutputs().ToArray();
            _arg_params   = null;
            _aux_params   = null;
            _params_dirty = false;

            _compression_params = compression_params;
            _optimizer          = null;
            _kvstore            = null;
            _update_on_kvstore  = null;
            _updater            = null;
            _preload_opt_states = null;
            _grad_req           = OpGradReq.Null;

            _exec_group   = null;
            _data_shapes  = null;
            _label_shapes = null;
        }
예제 #26
0
        public override void InitOptimizer(string kv = "local", Optimizer optimizer = null,
                                           Dictionary <string, object> optimizer_params = null, bool force_init = false)
        {
            if (!Binded && !ParamsInitialized)
            {
                throw new Exception("Module not binded and param initialized");
            }

            if (OptimizerInitialized && !force_init)
            {
                Logger.Warning("optimizer already initialized, ignoring...");
                return;
            }

            if (optimizer == null)
            {
                optimizer = new SGD();
            }

            if (_params_dirty)
            {
                SyncParamsFromDevices();
            }

            var(kvstore, update_on_kvstore) = Model.CreateKVStore(kv, _context.Length, _arg_params);
            var batch_size = _exec_group.BatchSize;

            if (kvstore != null && kvstore.Type.Contains("dist") && kvstore.Type.Contains("_sync"))
            {
                batch_size *= kvstore.NumWorkers;
            }

            var rescale_grad = 1.0 / batch_size;
            var idx2name     = new Dictionary <int, string>();

            if (update_on_kvstore)
            {
                var i = 0;
                foreach (var name in _exec_group.ParamNames)
                {
                    idx2name.Add(i, name);
                    i++;
                }
            }
            else
            {
                for (var k = 0; k < _context.Length; k++)
                {
                    var i = 0;
                    foreach (var name in _exec_group.ParamNames)
                    {
                        idx2name.Add(i * _context.Length + k, name);
                        i++;
                    }
                }
            }

            if (optimizer.RescaleGrad != rescale_grad)
            {
                Logger.Warning("Optimizer created manually outside Module but rescale_grad " +
                               $"is not normalized to 1.0/batch_size/num_workers ({optimizer.RescaleGrad} vs. {rescale_grad}). Is this intended?");
            }

            if (optimizer.Idx2Name == null)
            {
                optimizer.Idx2Name = idx2name;
            }

            _optimizer         = optimizer;
            _kvstore           = kvstore;
            _update_on_kvstore = update_on_kvstore;
            _updater           = null;
            if (kvstore != null)
            {
                if (_compression_params != null)
                {
                    kvstore.SetGradientCompression(_compression_params);
                }

                if (update_on_kvstore)
                {
                    kvstore.SetOptimizer(_optimizer);
                }

                Model.InitializeKVStore(kvstore, _exec_group.ParamArrays, _arg_params, _param_names, update_on_kvstore);
            }

            if (!update_on_kvstore)
            {
                _updater = optimizer.GetUpdater();
            }

            OptimizerInitialized = true;
            if (!string.IsNullOrWhiteSpace(_preload_opt_states))
            {
                LoadOptimizerStates(_preload_opt_states);
                _preload_opt_states = "";
            }
        }
예제 #27
0
 public void SetUp()
 {
     KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new KeyValueStorage.Redis.RedisStoreProvider(new ServiceStack.Redis.RedisClient())));
 }
예제 #28
0
        public void SetUp()
        {
            string connString = @"data source=localhost\SQLEXPRESS;initial catalog=Test;User Id=Test;Password=test";

            KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new SqlServerStoreProvider(connString)));
        }
예제 #29
0
        public void SetUp()
        {
            string connString = "data source=ORCL;password=x;persist security info=True;user id=x";

            KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new OracleStoreProvider(connString)));
        }
예제 #30
0
 public void SetUp()
 {
     KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new SimpleMemoryStoreProvider()));
 }
예제 #31
0
 public void SetUp()
 {
     KVStore.Initialize(new Func <Interfaces.IStoreProvider>(() => new LibGitStoreProvider(@"Git\G1")));
 }