@@ -190,17 +190,16 @@ async def handle_response(resp):
190
190
bt .logging .trace (f"Streamed text: { chunk } " )
191
191
192
192
# Store the query and response in the shared database
193
- async with self .lock :
194
- self .query_database .append ({
195
- 'uid' : uid ,
196
- 'synapse' : query_syn ,
197
- 'response' : (response_text , query_syn .dendrite .process_time ),
198
- 'query_type' : 'organic' ,
199
- 'timestamp' : asyncio .get_event_loop ().time (),
200
- 'validator' : ValidatorRegistryMeta .get_class ('TextValidator' )(config = self .config ,
201
- metagraph = self .metagraph )
202
- })
203
- query_syn .time_taken = query_syn .dendrite .process_time
193
+ self .query_database .append ({
194
+ 'uid' : uid ,
195
+ 'synapse' : query_syn ,
196
+ 'response' : (response_text , query_syn .dendrite .process_time ),
197
+ 'query_type' : 'organic' ,
198
+ 'timestamp' : asyncio .get_event_loop ().time (),
199
+ 'validator' : ValidatorRegistryMeta .get_class ('TextValidator' )(config = self .config ,
200
+ metagraph = self .metagraph )
201
+ })
202
+ query_syn .time_taken = query_syn .dendrite .process_time
204
203
205
204
axon = self .metagraph .axons [uid ]
206
205
response = self .dendrite .call_stream (
@@ -256,15 +255,14 @@ def is_cycle_end(self):
256
255
async def perform_synthetic_queries_one_cycle (self ):
257
256
start_time = time .time ()
258
257
# don't process any organic query while processing synthetic queries.
259
- async with self .lock :
260
- synthetic_tasks = []
261
- # check available bandwidth and send synthetic requests to all miners.
262
- query_synapses = await self .create_query_syns_for_remaining_bandwidth ()
263
- for query_syn in query_synapses :
264
- uid = self .task_mgr .assign_task (query_syn )
265
- if uid is None :
266
- bt .logging .debug (f"No available uids for synthetic query process." )
267
- synthetic_tasks .append ((uid , self .query_miner (uid , query_syn , organic = False )))
258
+ synthetic_tasks = []
259
+ # check available bandwidth and send synthetic requests to all miners.
260
+ query_synapses = await self .create_query_syns_for_remaining_bandwidth ()
261
+ for query_syn in query_synapses :
262
+ uid = self .task_mgr .assign_task (query_syn )
263
+ if uid is None :
264
+ bt .logging .debug (f"No available uids for synthetic query process." )
265
+ synthetic_tasks .append ((uid , self .query_miner (uid , query_syn , organic = False )))
268
266
269
267
bt .logging .debug (f"{ time .time () - start_time } elapsed for creating and submitting synthetic queries." )
270
268
@@ -364,13 +362,12 @@ async def update_weights(self):
364
362
avg_scores = {}
365
363
366
364
# Compute average scores per UID
367
- async with self .lock :
368
- for uid in self .total_scores :
369
- count = self .score_counts [uid ]
370
- if count > 0 :
371
- avg_scores [uid ] = self .total_scores [uid ] / count
372
- else :
373
- avg_scores [uid ] = 0.0
365
+ for uid in self .total_scores :
366
+ count = self .score_counts [uid ]
367
+ if count > 0 :
368
+ avg_scores [uid ] = self .total_scores [uid ] / count
369
+ else :
370
+ avg_scores [uid ] = 0.0
374
371
375
372
bt .logging .info (f"Average scores = { avg_scores } " )
376
373
@@ -444,16 +441,15 @@ async def images(self, synapse: ImageResponse) -> ImageResponse:
444
441
445
442
bt .logging .info (f"New synapse = { synapse_response } " )
446
443
# Store the query and response in the shared database
447
- async with self .lock :
448
- self .query_database .append ({
449
- 'uid' : synapse .uid ,
450
- 'synapse' : synapse ,
451
- 'response' : synapse_response ,
452
- 'query_type' : 'organic' ,
453
- 'timestamp' : asyncio .get_event_loop ().time (),
454
- 'validator' : ValidatorRegistryMeta .get_class ('ImageValidator' )(config = self .config ,
455
- metagraph = self .metagraph )
456
- })
444
+ self .query_database .append ({
445
+ 'uid' : synapse .uid ,
446
+ 'synapse' : synapse ,
447
+ 'response' : synapse_response ,
448
+ 'query_type' : 'organic' ,
449
+ 'timestamp' : asyncio .get_event_loop ().time (),
450
+ 'validator' : ValidatorRegistryMeta .get_class ('ImageValidator' )(config = self .config ,
451
+ metagraph = self .metagraph )
452
+ })
457
453
458
454
return synapse_response
459
455
@@ -466,16 +462,15 @@ async def embeddings(self, synapse: Embeddings) -> Embeddings:
466
462
467
463
bt .logging .info (f"New synapse = { synapse_response } " )
468
464
# Store the query and response in the shared database
469
- async with self .lock :
470
- self .query_database .append ({
471
- 'uid' : synapse .uid ,
472
- 'synapse' : synapse ,
473
- 'response' : synapse_response ,
474
- 'query_type' : 'organic' ,
475
- 'timestamp' : asyncio .get_event_loop ().time (),
476
- 'validator' : ValidatorRegistryMeta .get_class ('EmbeddingsValidator' )(config = self .config ,
477
- metagraph = self .metagraph )
478
- })
465
+ self .query_database .append ({
466
+ 'uid' : synapse .uid ,
467
+ 'synapse' : synapse ,
468
+ 'response' : synapse_response ,
469
+ 'query_type' : 'organic' ,
470
+ 'timestamp' : asyncio .get_event_loop ().time (),
471
+ 'validator' : ValidatorRegistryMeta .get_class ('EmbeddingsValidator' )(config = self .config ,
472
+ metagraph = self .metagraph )
473
+ })
479
474
480
475
return synapse_response
481
476
@@ -509,17 +504,16 @@ async def handle_response(resp):
509
504
bt .logging .trace (f"Streamed text: { chunk } " )
510
505
511
506
# Store the query and response in the shared database
512
- async with self .lock :
513
- self .query_database .append ({
514
- 'uid' : synapse .uid ,
515
- 'synapse' : synapse ,
516
- 'response' : (response_text , synapse .dendrite .process_time ),
517
- 'query_type' : 'organic' ,
518
- 'timestamp' : asyncio .get_event_loop ().time (),
519
- 'validator' : ValidatorRegistryMeta .get_class ('TextValidator' )(config = self .config ,
520
- metagraph = self .metagraph )
521
- })
522
- synapse .time_taken = self .dendrite .process_time
507
+ self .query_database .append ({
508
+ 'uid' : synapse .uid ,
509
+ 'synapse' : synapse ,
510
+ 'response' : (response_text , synapse .dendrite .process_time ),
511
+ 'query_type' : 'organic' ,
512
+ 'timestamp' : asyncio .get_event_loop ().time (),
513
+ 'validator' : ValidatorRegistryMeta .get_class ('TextValidator' )(config = self .config ,
514
+ metagraph = self .metagraph )
515
+ })
516
+ synapse .time_taken = synapse .dendrite .process_time
523
517
524
518
await send ({"type" : "http.response.body" , "body" : b'' , "more_body" : False })
525
519
@@ -605,9 +599,8 @@ async def process_queries_from_database(self):
605
599
606
600
bt .logging .info (f"start scoring process..." )
607
601
608
- async with self .lock :
609
- queries_to_process = self .query_database .copy ()
610
- self .query_database .clear ()
602
+ queries_to_process = self .query_database .copy ()
603
+ self .query_database .clear ()
611
604
612
605
self .synthetic_task_done = False
613
606
bt .logging .info ("start scoring process" )
@@ -619,12 +612,11 @@ async def process_queries_from_database(self):
619
612
resps = await asyncio .gather (* score_tasks )
620
613
resps = [item for item in resps if item is not None ]
621
614
# Update total_scores and score_counts
622
- async with self .lock :
623
- for uid_scores_dict , _ , _ in resps :
624
- for uid , score in uid_scores_dict .items ():
625
- if self .total_scores .get (uid ) is not None :
626
- self .total_scores [uid ] += score
627
- self .score_counts [uid ] += 1
615
+ for uid_scores_dict , _ , _ in resps :
616
+ for uid , score in uid_scores_dict .items ():
617
+ if self .total_scores .get (uid ) is not None :
618
+ self .total_scores [uid ] += score
619
+ self .score_counts [uid ] += 1
628
620
bt .logging .info (
629
621
f"current total score are { self .total_scores } . total time of scoring is { time .time () - start_time } " )
630
622
self .saving_datas = queries_to_process .copy ()
0 commit comments