ray-project / ray

Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI Libraries for accelerating ML workloads.
https://ray.io
Apache License 2.0
33.06k stars 5.6k forks source link

AttributeError: module 'ray.tune' has no attribute 'report' #8991

Closed smilesun closed 4 years ago

smilesun commented 4 years ago

What is your question?

Ray version 0.8.5 pytorch version 1.0.1.post2 OS: Ubuntu 18

I copied the tutorial from https://docs.ray.io/en/master/tune.html#tune-index into an empty python file tune.py then I call python tune.py, I got the following error in the error log file I checked separatedly, ray.tune on my machine indeed does not have a "report" method, anything I did wrong for installation? I just did as the tutorial said pip install 'ray[tune]'

Failure # 1 (occurred at 2020-06-17_11-54-03)                                                                                                 
  2 Traceback (most recent call last):                                                                                                            
  3   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/trial_runner.py", line 467, in _process_trial                              
  4     result = self.trial_executor.fetch_result(trial)                                                                                          
  5   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/ray_trial_executor.py", line 431, in fetch_result                          
  6     result = ray.get(trial_future[0], DEFAULT_GET_TIMEOUT)                                                                                    
  7   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/worker.py", line 1515, in get                                                   
  8     raise value.as_instanceof_cause()                                                                                                         
  9 ray.exceptions.RayTaskError(TuneError): ^[[36mray::WrappedTrackFunc.train()^[[39m (pid=14553, ip=192.168.128.251)                             
 10   File "python/ray/_raylet.pyx", line 463, in ray._raylet.execute_task                                                                        
 11   File "python/ray/_raylet.pyx", line 417, in ray._raylet.execute_task.function_executor                                                      
 12   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/trainable.py", line 261, in train                                          
 13     result = self._train()                                                                                                                    
 14   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/function_runner.py", line 216, in _train                                   
 15     self._report_thread_runner_error(block=True)                                                                                              
 16   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/function_runner.py", line 259, in _report_thread_runner_error              
 17     .format(err_tb_str)))                                                                                                                     
 18 ray.tune.error.TuneError: Trial raised an exception. Traceback:                                                                               
 19 ^[[36mray::WrappedTrackFunc.train()^[[39m (pid=14553, ip=192.168.128.251)                                                                     
 20   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/function_runner.py", line 110, in run                                      
 21     self._entrypoint()                                                                                                                        
 22   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/function_runner.py", line 162, in entrypoint                               
 23     return self._trainable_func(config, self._status_reporter)                                                                                
 24   File "/home/xxx/anaconda3/lib/python3.7/site-packages/ray/tune/function_runner.py", line 288, in _trainable_func                          
 25     output = train_func(config)                                                                                                               
 26   File "tune.py", line 13, in train_mnist                                                                                                     
 27     tune.report(mean_accuracy=acc)                                                                                                            
 28 AttributeError: module 'ray.tune' has no attribute 'report'                                                                                   
 29        
richardliaw commented 4 years ago

@smilesun sorry for the confusion. Here is the documentation to the latest pip release. tune.report is not available there yet (and instead should be tune.track.log) - https://docs.ray.io/en/latest/tune.html

If you want to install from master, use the latest nightly wheels: https://docs.ray.io/en/master/installation.html#latest-snapshots-nightlies

tune.report is going to replace tune.track.log in future versions of Ray.

smilesun commented 4 years ago

thanks!

mirekphd commented 4 years ago

Hi @smilesun ,

Please note that some of your examples also need to be updated after this API change from report to track.log (maybe they could be even incorporated / converted to unit tests?): https://github.com/ray-project/ray/search?q=tune.report&type=Code

I'd reopen the issue to prevent this getting forgotten:)

richardliaw commented 4 years ago

For clarity - tune.track.log is being changed to tune.report in 0.8.6.

richardliaw commented 4 years ago

This should be addressed in the future by #9427

Ansilins commented 4 months ago

Am using kaggle to train my model , Ray -- Version: 2.6.3 Ultralytics --version 8.2.6

Error: AttributeError Traceback (most recent call last) Cell In[3], line 9 6 model = YOLO("yolov5s.yaml") 8 # Train the model ----> 9 metrics = model.train(data='/kaggle/input/newcreare/data.yaml', epochs=30, verbose=True) 12 # Save the trained model 13 model.save("yolov5_ans.pt")

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/model.py:673, in Model.train(self, trainer, **kwargs) 670 pass 672 self.trainer.hub_session = self.session # attach optional HUB session --> 673 self.trainer.train() 674 # Update model and cfg after training 675 if RANK in {-1, 0}:

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/trainer.py:199, in BaseTrainer.train(self) 196 ddp_cleanup(self, str(file)) 198 else: --> 199 self._do_train(world_size)

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/trainer.py:440, in BaseTrainer._do_train(self, world_size) 438 self.scheduler.last_epoch = self.epoch # do not move 439 self.stop |= epoch >= self.epochs # stop if exceeded epochs --> 440 self.run_callbacks("on_fit_epoch_end") 441 gc.collect() 442 torch.cuda.empty_cache() # clear GPU memory at end of epoch, may help reduce CUDA out of memory errors

File /opt/conda/lib/python3.10/site-packages/ultralytics/engine/trainer.py:162, in BaseTrainer.run_callbacks(self, event) 160 """Run all existing callbacks associated with a particular event.""" 161 for callback in self.callbacks.get(event, []): --> 162 callback(self)

File /opt/conda/lib/python3.10/site-packages/ultralytics/utils/callbacks/raytune.py:17, in on_fit_epoch_end(trainer) 15 def on_fit_epoch_end(trainer): 16 """Sends training metrics to Ray Tune at end of each epoch.""" ---> 17 if ray.train._internal.session._get_session(): # replacement for deprecated ray.tune.is_session_enabled() 18 metrics = trainer.metrics 19 metrics["epoch"] = trainer.epoch

AttributeError: module 'ray.train._internal.session' has no attribute '_get_session'

umarbutler commented 3 months ago

^ Same issue.

umarbutler commented 3 months ago

@Ansilins I've discovered that this was fixed in v8.1.38 of ultralytics. If you can't update because you're using YOLOv10, a temporary hotfix is to go into ultralytics/utils/callbacks/raytune.py and update a single line of code as was done for v8.1.38 of Ultralytics: https://github.com/ultralytics/ultralytics/commit/1828cfe842eb45b9d4c098fda99d2515835b861b

See also https://github.com/THU-MIG/yolov10/issues/59

Ansilins commented 3 months ago

Thank you @umarbutler