o
    nio                     @   s   d dl Z d dlmZmZmZmZmZ d dlmZ d dl	m
Z
mZ edeeef Z	 dZG dd dZd	ejd
ee fddZdddeeef dee ded
eeeef  fddZdS )    N)AnyDictNewTypeOptionalSequence)wandb_internal_pb2)
proto_util	telemetryBackendConfigDict_wandbc                   @   s   e Zd ZdZddeeeef  ddfddZdeeef fddZ	d	e
jddfd
dZdeeef ddfddZdeeef dee ddfddZdejdee dedeeeef  def
ddZdee deddfddZdee ddfddZdS )ConfigStatezThe configuration of a run.Ntreereturnc                 C   s   |pi | _ d S N)_tree)selfr    r   ^/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/sdk/internal/sender_config.py__init__   s   
zConfigState.__init__c                 C   s   dd | j  D S )z+Returns the config settings minus "_wandb".c                 S   s   i | ]\}}|t kr||qS r   )_WANDB_INTERNAL_KEY).0kvr   r   r   
<dictcomp>   s    z3ConfigState.non_internal_config.<locals>.<dictcomp>)r   items)r   r   r   r   non_internal_config   s   zConfigState.non_internal_configconfig_recordc                 C   sB   |j D ]}| t|t|j q|jD ]	}| t| qdS )z#Applies update and remove commands.N)update_update_at_path	_key_pathjsonloads
value_jsonremove_delete_at_path)r   r   config_itemr   r   r   update_from_proto   s   


zConfigState.update_from_protoold_config_treec                 C   s0   |  |g  |  |tdg |  |tdg dS )z2Merges the config from a run that's being resumed.	visualizevizN)_add_unset_keys_from_subtreer   )r   r'   r   r   r   merge_resumed_config-   s   z ConfigState.merge_resumed_configpathc                 C   sX   t ||dd}|sdS t | j|dd}|dusJ | D ]\}}||vr)|||< qdS )z8Uses the given subtree for keys that aren't already set.FcreateNT)_subtreer   r   )r   r'   r,   old_subtreenew_subtreekeyvaluer   r   r   r*   >   s   z(ConfigState._add_unset_keys_from_subtreetelemetry_record	frameworkstart_time_millismetric_pbdictsc           
      C   s   | j  }|ti }|j}|r||d< |j}|r||d< |r#||d< |j}	|	r,|	|d< |jj|d< |jj	|d< ||d< t
||d< |rI||d	< td
d | j  D S )a  Returns a dictionary representation expected by the backend.

        The backend expects the configuration in a specific format, and the
        config is also used to store additional metadata about the run.

        Args:
            telemetry_record: Telemetry information to insert.
            framework: The detected framework used in the run (e.g. TensorFlow).
            start_time_millis: The run's start time in Unix milliseconds.
            metric_pbdicts: List of dict representations of metric protobuffers.
        python_versioncli_versionr5   huggingface_versionis_jupyter_runis_kaggle_kernel
start_timetmc                 S   s   i | ]
\}}|d |dqS )N)descr3   r   )r   r2   r3   r   r   r   r      s    	z/ConfigState.to_backend_dict.<locals>.<dictcomp>)r   copy
setdefaultr   r8   r9   r:   envjupyterkaggler   proto_encode_to_dictr
   r   )
r   r4   r5   r6   r7   backend_dictwandb_internal
py_versionr9   r:   r   r   r   to_backend_dictO   s0   
	zConfigState.to_backend_dictkey_pathr3   c                 C   s4   t | j|dd dd}|dusJ |||d < dS )z.Sets the value at the path in the config tree.NTr-   r/   r   )r   rK   r3   subtreer   r   r   r      s   zConfigState._update_at_pathc                 C   s.   t | j|dd dd}|r||d = dS dS )z3Removes the subtree at the path in the config tree.NrL   Fr-   rM   )r   rK   rN   r   r   r   r$      s   zConfigState._delete_at_pathr   )__name__
__module____qualname____doc__r   r   strr   r   r   r   ConfigRecordr&   r+   r   r*   r	   TelemetryRecordintr
   rJ   r   r$   r   r   r   r   r      sP     



B
r   r%   r   c                 C   s"   | j r| j S | jr| jgS td)z3Returns the key path referenced by the config item.z8Invalid ConfigItem: either key or nested_key must be set)
nested_keyr2   AssertionError)r%   r   r   r   r      s   r   Fr-   r   rK   r.   c                C   s8   |D ]}|  |}|s|ri }|| |< n dS |} q| S )z$Returns a subtree at the given path.N)get)r   rK   r.   r2   rN   r   r   r   r/      s   

r/   )r    typingr   r   r   r   r   wandb.protor   wandb.sdk.libr   r	   rS   r
   r   r   
ConfigItemr   boolr/   r   r   r   r   <module>   s(     
