o
    -wi                     @   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
j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/sommelier/.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   s*   |  |g  dD ]
}|  |t|g qdS )z2Merges the config from a run that's being resumed.)viz	visualizezmask/class_labelsN)_add_unset_keys_from_subtreer   )r   r'   keyr   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_subtreer+   valuer   r   r   r*   ;   s   z(ConfigState._add_unset_keys_from_subtreetelemetry_record	frameworkstart_time_millismetric_pbdictsenvironment_recordc                 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	< |j}|rYt
|}||i|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mec                 S   s   i | ]
\}}|d |dqS )N)descr3   r   )r   r+   r3   r   r   r   r      s    	z/ConfigState.to_backend_dict.<locals>.<dictcomp>)r   copy
setdefaultr   r9   r:   r;   envjupyterkaggler   proto_encode_to_dict	writer_idmessage_to_dictr
   r   )r   r4   r5   r6   r7   r8   backend_dictwandb_internal
py_versionr:   r;   rI   environment_dictr   r   r   to_backend_dictL   s8   

	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.   r0   r   )r   rP   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.NrQ   Fr.   rR   )r   rP   rS   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intEnvironmentRecordr
   rO   r   r$   r   r   r   r   r      sT     



K
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_keyr+   AssertionError)r%   r   r   r   r      s   r   Fr.   r   rP   r/   c                C   s8   |D ]}|  |}|s|ri }|| |< n dS |} q| S )z$Returns a subtree at the given path.N)get)r   rP   r/   r+   rS   r   r   r   r0      s   

r0   )r    typingr   r   r   r   r   wandb.protor   wandb.sdk.libr   r	   rX   r
   r   r   
ConfigItemr   boolr0   r   r   r   r   <module>   s(      
