lfwa / carbontracker

Track and predict the energy consumption and carbon footprint of training deep learning models.
MIT License
350 stars 27 forks source link

Errors #52

Closed hrv897 closed 10 months ago

hrv897 commented 1 year ago

When running carbon tracker like this:

tracker = CarbonTracker(epochs=100)

correct = 0 wrong = 0 tracker.epoch_start() for i in range(100): true_label = id2label[val_labels[i].item()] img = T.ToPILImage()(val_features[i].squeeze()) inputs = processor(images=img, return_tensors="pt").to(device) pixel_values = inputs.pixel_values

outputs = model(pixel_values) logits = outputs.logits logits.shape prediction = logits.argmax(-1) prediction_str = model.config.id2label[prediction.item()]

display(img) print("Predicted class:", prediction_str) print("True class:", true_label) if true_label == prediction_str: correct += 1 print("correct") else: wrong += 1 print("wrong")

tracker.epoch_end() tracker.stop()

On an Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz with 16 GB RAM, NVIDIA GeForce GTX 980 Ti and Windows 10 in Jupyter Notebook, I get the following output from CarbonTracker:

CarbonTracker: Actual consumption for 1 epoch(s): Time: 0:00:05 Energy: 0.000152 kWh CO2eq: 0.006405 g This is equivalent to: 0.000060 km travelled by car CarbonTracker: INFO - Traceback (most recent call last): File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\requests\models.py", line 971, in json return complexjson.loads(self.text, **kwargs) File "C:\Users\user\anaconda3\envs\gpu2\lib\json__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Users\user\anaconda3\envs\gpu2\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\user\anaconda3\envs\gpu2\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\intensity.py", line 117, in carbon_intensity carbon_intensity = fetcher.carbon_intensity(g_location, time_dur) File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\fetchers\energidataservice.py", line 21, in carbon_intensity ci = self._emission_prognosis(time_dur=time_dur) File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\fetchers\energidataservice.py", line 48, in _emission_prognosis raise exceptions.CarbonIntensityFetcherError(response.json()) File "C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\requests\models.py", line 975, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

CarbonTracker: Predicted consumption for 100 epoch(s): Time: 0:08:26 Energy: 0.015250 kWh CO2eq: 1.462028 g This is equivalent to: 0.013600 km travelled by car CarbonTracker: Finished monitoring.

raghavian commented 1 year ago

Looks like the energiservice api which we use to query the carbon emissions changed their string format. We will release a bug fix. For now, if you change the query method in energidataservice.py in your local installation it should work. You can find this in your installation here C:\Users\user\anaconda3\envs\gpu2\lib\site-packages\carbontracker\emissions\intensity\intensity.py

    def _emission_prognosis(self, time_dur):
        from_str, to_str = self._interval(time_dur=time_dur)
        from_str = from_str.replace(' ','T')
        to_str = to_str.replace(' ','T')
        url = "https://api.energidataservice.dk/dataset/CO2Emis?start=" + from_str + "&end=" + to_str + "&limit=4"
        response = requests.get(url)
        if not response.ok:
            raise exceptions.CarbonIntensityFetcherError(response.json())
        data = response.json()["records"]
        carbon_intensities = [record["CO2Emission"] for record in data]
        return np.mean(carbon_intensities)
dmdequin commented 1 year ago

The function _emission_prognosis is found in carbontracker/emissions/intensity/fetchers/energidataservice.py. The path shown above is incorrect.

PedramBakh commented 10 months ago

This issue has been addressed in Release v1.2.0. We've phased out support for the energidataserviceapi and transitioned to the ElectricityMaps API. This change ensures better consistency and resolves the timeout issues previously encountered with consecutive requests. Thank you for bringing this to our attention.