o
    xi/                    @  s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZ d dlmZmZmZmZ d dlm Z m!Z!m"Z" d d	l#m$Z$ d dl%Z%d d
l%m&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6 ddl7m8Z8m9Z9m:Z: ddl;m<Z< e)sd dlm=Z= d!ddZ>dZ?	 G dd de ddZ@d"dd ZAdS )#    )annotationsN)Sequence)datetime)AnyDictListLiteralOptionalTupleUnion)quoteunquote)	BoolValueDoubleValue
Int32ValueStringValue)	BaseModel
ConfigDictField)Self)envutil)IS_PYDANTIC_V2AliasChoicesValidationErrorcomputed_fieldfield_validatormodel_validator
UsageError)wandb_settings_pb2)deprecationsettings_fileurls   )credentials
filesystemipython)	RunMoment)root_validatorargsstrreturnc                  G  s   t jt jj|  S )z-Join path and apply os.path.expanduser to it.)ospath
expanduserjoin)r*    r1   L/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/wandb_settings.py_path_convert0   s   r3   )	anonymousapp_url_override	files_dirmax_end_of_run_history_metricsmax_end_of_run_summary_metricsreinitx_files_dirx_sync_dir_suffixc                   @  sN  e Zd ZU dZedddddZdZded< 	 dZded	< 	 e	e
jdd
Zded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 e	dddZded< 	 dZded< 	 dZded < 	 dZded!< 	 e	d"d# d$Zded%< 	 dZded&< 	 dZded'< 	 dZded(< 	 dZded)< 	 dZded*< 	 dZded+< 	 dZded,< 	 dZded-< 	 dZ d.ed/< 	 dZ!ded0< 	 d1Z"ded2< 	 dZ#ded3< 	 dZ$ded4< 	 d5Z%ded6< 	 dZ&ded7< 	 dZ'ded8< 	 dZ(ded9< 	 dZ)ded:< 	 d;Z*d<ed=< 	 d>Z+d?ed@< 	 dZ,dedA< 	 dZ-dedB< 	 dZ.dCedD< 	 dZ/dedE< 	 dZ0dedF< 	 dZ1dedG< 	 dZ2dHedI< 	 e	dJddZ3dKedL< 	 dZ4dedM< 	 dZ5dedN< 	 dZ6dedO< 	 dZ7dedP< 	 dZ8dedQ< 	 dZ9dedR< 	 dSZ:dTedU< 	 dZ;dedV< 	 dZ<dWedX< 	 dZ=d.edY< 	 dZ>dedZ< 	 e	d[d# d$Z?ded\< 	 dZ@ded]< 	 dZAded^< 	 dZBded_< 	 dZCded`< 	 dZDdeda< 	 dZEdbedc< 	 dZFdedd< 	 dZGdeedf< 	 dZHdedg< 	 dhZIdedi< 	 dhZJdedj< 	 dZKdeedk< 	 dZLdeedl< 	 dZMdedm< 	 dZNdedn< 	 dZOdedo< 	 dZPdedp< 	 dZQdedq< 	 dZRdeedr< 	 dsZSdedt< 	 duZTdedv< 	 dZUdedw< 	 dZVdedx< 	 e	dyd# d$ZWdedz< 	 dZXdeed{< 	 dZYded|< 	 dZZdeed}< 	 dZ[ded~< 	 dZ\ded< 	 dZ]ded< 	 dZ^ded< 	 dZ_ded< 	 dZ`ded< 	 dZaded< 	 dZbded< 	 dZcded< 	 dZdded< 	 dZedHed< 	 dZfded< 	 dZgdHed< 	 dZhdHed< 	 dZidHed< 	 dZjded< 	 dZkdHed< 	 dZldHed< 	 dZmdHed< 	 dZnded< 	 dZodeed< 	 dZpdeed< 	 dZqded< 	 dZrdHed< 	 dZsdHed< 	 dZtdHed< 	 dZud?ed< 	 dZvded< 	 dZwded< 	 dZxded< 	 dZyded< 	 dZzded< 	 dZ{ded< 	 e|j}Z~ded< 	 dZded< 	 e	dedddZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZd?ed< 	 dZded< 	 dZdHed< 	 e Zded< 	 e	ddZd?ed< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 dZded< 	 edd͍eddτ ZerYedd͍dddԄZedd͍ddք Znedd׍eddԄ Zedd׍eddք Zeddd͍eddd݄Zeddd͍edd߄ Zeddd͍edd Zeddd͍edd Zeddd͍edd Zed dd͍edd Zed!dd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zed/dd͍edddZed8dd͍edd Zed9dd͍edd Zed=dd͍edd ZedNdd͍edd ZedOdd͍edd ZedPdd͍edd ZedQdd͍ed d ZedXdd͍edd ZedYdd͍edddZed\dd͍edd Zed^dd͍edd	 Zedgdd͍ed
d Zeddd͍edd Zedqdd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zeddd͍edd Zedwdd͍edd Zedcdd͍ed d! Zedxdd͍ed"d# Zeeΐdd%d&Zeeΐdd'd(Zeeΐdd)d*Zeeΐdd+d,Zeeΐdd-d.Zeeΐdd/d0Zeeΐdd1d2Zeeΐdd3d4Zeeΐdd5d6Zeeΐdd7d8Zeeΐdd9d:Zeeΐdd;d<Zeeΐdd=d>Zeeΐdd?d@ZeeΐddAdBZeeΐddCdDZeeΐddEdFZeeΐddGdHZeeΐddIdJZeeΐddLdMZeeΐddNdOZeeΐddPdQZeeΐddRdSZeeΐddTdUZeeΐddVdWZeeΐddXdYZeeΐddZd[Zeeΐdd\d]Zeeΐdd^d_ZeeΐddadbZeeΐddcddZeeΐddedfZeeΐddgdhZeeΐddidjZeeΐddkdlZeeΐddmdnZeeΐddodpZeeΐddqdrZddtduZddwdxZdd{d|Zd}d~ ZdddZdddZdddZdddZeddddZdddZedddZ esdd Zdd ZeΐdddZdddZdddZdddZdS (  Settingsa  Settings for the W&B SDK.

    This class manages configuration settings for the W&B SDK,
    ensuring type safety and validation of all settings. Settings are accessible
    as attributes and can be initialized programmatically, through environment
    variables (`WANDB_ prefix`), and with configuration files.

    The settings are organized into three categories:
    1. Public settings: Core configuration options that users can safely modify to customize
       W&B's behavior for their specific needs.
    2. Internal settings: Settings prefixed with 'x_' that handle low-level SDK behavior.
       These settings are primarily for internal use and debugging. While they can be modified,
       they are not considered part of the public API and may change without notice in future
       versions.
    3. Computed settings: Read-only settings that are automatically derived from other settings or
       the environment.
    forbidTalways)extravalidate_defaultuse_attribute_docstringsrevalidate_instancesboolallow_offline_artifactsFallow_val_change)defaultexcludezdeprecation.DoNotSetr4   NOptional[str]api_keyzOptional[Dict[str, str]]azure_account_url_to_access_keyr5   https://api.wandb.air+   base_urlcode_dirzOptional[Sequence[str]]config_pathsauto)rF   r@   zBLiteral['auto', 'off', 'wrap', 'redirect', 'wrap_raw', 'wrap_emu']consoleconsole_multipartr   intconsole_chunk_max_bytesconsole_chunk_max_secondsc                   C  s
   t tjS N)r+   r%   DEFAULT_WANDB_CREDENTIALS_FILEr1   r1   r1   r2   <lambda>   s   
 zSettings.<lambda>)default_factorycredentials_filedisable_codedisable_gitdisable_job_creationdockeremailentityorganizationforceOptional[RunMoment]	fork_from
git_commitorigin
git_remotegit_remote_urlgit_root   heartbeat_secondshost
http_proxyhttps_proxyidentity_token_filer1   zSequence[str]ignore_globsg     V@floatinit_timeoutinsecure_disable_ssljob_namez.Optional[Literal['repo', 'artifact', 'image']]
job_sourcelabel_disablelaunchlaunch_config_pathzOptional[float]login_timeoutonlinezCLiteral['online', 'offline', 'shared', 'disabled', 'dryrun', 'run']modenotebook_nameprogramprogram_abspathprogram_relpathprojectquietrF   zSUnion[Literal['default', 'return_previous', 'finish_previous', 'create_new'], bool]r9   reloginz3Optional[Literal['allow', 'must', 'never', 'auto']]resumeresume_fromresumedc                   C  s   t jt  S rU   )r-   r.   abspathgetcwdr1   r1   r1   r2   rW   t  s    root_dir	run_grouprun_idrun_job_typerun_name	run_noteszOptional[Tuple[str, ...]]run_tagssagemaker_disablezOptional[bool]	save_codesettings_system
   r7   r8   show_colors
show_emojishow_errors	show_infoshow_warningssilentstart_methodstrict<   summary_timeout   summary_warningssweep_idsweep_param_pathc                   C  s   t  dkS NWindowsplatformsystemr1   r1   r1   r2   rW     s    symlinksync_tensorboard%table_raise_on_max_row_limit_exceededuse_dot_wandbusernamex_cli_only_modex_disable_metax_disable_statsx_disable_viewerx_disable_machine_infox_executablex_extra_http_headerszOptional[int]x_file_stream_max_bytesx_file_stream_max_line_bytesx_file_stream_transmit_intervalx_file_stream_retry_max$x_file_stream_retry_wait_min_seconds$x_file_stream_retry_wait_max_secondsx_file_stream_timeout_secondsx_file_transfer_retry_max&x_file_transfer_retry_wait_min_seconds&x_file_transfer_retry_wait_max_secondsx_file_transfer_timeout_secondsr:   x_flow_control_customx_flow_control_disabledx_graphql_retry_max x_graphql_retry_wait_min_seconds x_graphql_retry_wait_max_secondsx_graphql_timeout_secondsg       @x_internal_check_processx_jupyter_namex_jupyter_pathx_jupyter_rootx_labelx_live_policy_rate_limitx_live_policy_wait_timex_log_levelx_network_buffer	x_primaryx_primary_node)rF   validation_alias	x_proxiesx_runqueue_item_idx_save_requirementsx_server_side_derived_summary!x_server_side_expand_glob_metricsx_service_transportg      >@x_service_waitx_skip_transaction_logx_start_timex_stats_pidg      .@)rF   x_stats_sampling_interval"x_stats_neuron_monitor_config_pathx_stats_dcgm_exporterx_stats_open_metrics_endpointsz5Union[Dict[str, Dict[str, str]], Sequence[str], None]x_stats_open_metrics_filters!x_stats_open_metrics_http_headers)/x_stats_disk_pathsx_stats_cpu_countx_stats_cpu_logical_countx_stats_gpu_countx_stats_gpu_typezOptional[Sequence[int]]x_stats_gpu_device_idsx_stats_buffer_sizezhttp://169.254.169.254#x_stats_coreweave_metadata_base_urlz/api/v2/cloud-init/meta-data#x_stats_coreweave_metadata_endpointx_stats_track_process_treex_sync r;   x_update_finish_statebeforerz   c                 C  s:   i }|D ]}| dr|| |d| < q|| ||< q|S )zCheck if a private field is provided and assign to the corresponding public one.

        This is a compatibility layer to handle previous versions of the settings.

        <!-- lazydoc-ignore-classmethod: internal -->
        _x)
startswith)clsvalues
new_valueskeyr1   r1   r2   catch_private_settings~  s   	
zSettings.catch_private_settingsafterr,   r   c                 C  s.   t dd | j| j| jfD dkrtd| S )zCheck if `fork_from`, `resume`, and `resume_from` are mutually exclusive.

            <!-- lazydoc-ignore: internal -->
            c                 s  s    | ]}|d uV  qd S rU   r1   .0or1   r1   r2   	<genexpr>  s
    
GSettings.validate_mutual_exclusion_of_branching_args.<locals>.<genexpr>r$   ``fork_from`, `resume`, or `resume_from` are mutually exclusive. Please specify only one of them.)sumrc   r   r   
ValueErrorselfr1   r1   r2   +validate_mutual_exclusion_of_branching_args  s   z4Settings.validate_mutual_exclusion_of_branching_argsc                 C  s   | j r
| jr
td| S )z\Validate x_skip_transaction_log.

            <!-- lazydoc-ignore: internal -->
            +Cannot skip transaction log in offline mode)_offliner   r   r   r1   r1   r2   validate_skip_transaction_log  s   z&Settings.validate_skip_transaction_log)prec                   s&   t  fdddD dkrtd S )Nc                 3  s    | ]
}  |d uV  qd S rU   )getr   r   r1   r2   r     s
    
r   )rc   r   r   r$   r   )r   r   r   r   r1   r  r2   r    s   c                 C  s    | dr| drtd|S )Nr  r   r  )r  r   r  r1   r1   r2   r    s   valueobjectc                 C  s   |t jurtjddd |S )NzLThe anonymous setting has no effect and will be removed in a future version.Frepeat)r!   UNSETwandbtermwarnr   r	  r1   r1   r2   validate_anonymous  s   
zSettings.validate_anonymousc                 C  s(   |durt |t | krtd|S )zUValidate the API key.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nz+API key cannot start or end with whitespace)lenstripr   r  r1   r1   r2   validate_api_key  s   zSettings.validate_api_keyc                 C  sT   t | td|rd|vrt| dtd|r%|ds%td|dS )zVValidate the base URL.

        <!-- lazydoc-ignore-classmethod: internal -->
        z.*wandb\.ai[^\.]*$zapi.zB is not a valid server address, did you mean https://api.wandb.ai?httpsz3http is not secure, please use https://api.wandb.air   )r#   validate_urlrematchr   r   rstripr  r1   r1   r2   validate_base_url  s   

zSettings.validate_base_urlc                 C     t |tjr
t|S |S )z\Validate the code directory.

        <!-- lazydoc-ignore-classmethod: internal -->
        
isinstancepathlibPathr+   r  r1   r1   r2   validate_code_dir     zSettings.validate_code_dirc                 C  s   |dkr|S dS )zdValidate the console capture method.

        <!-- lazydoc-ignore-classmethod: internal -->
        rO   wrapr1   r   r	  r   r1   r1   r2   validate_console  s   zSettings.validate_consolec                 C     |dk rt d|S )zkValidate the console_chunk_max_bytes value.

        <!-- lazydoc-ignore-classmethod: internal -->
        r   z,console_chunk_max_bytes must be non-negativer   r  r1   r1   r2    validate_console_chunk_max_bytes
     z)Settings.validate_console_chunk_max_bytesc                 C  r%  )zmValidate the console_chunk_max_seconds value.

        <!-- lazydoc-ignore-classmethod: internal -->
        r   z.console_chunk_max_seconds must be non-negativer&  r  r1   r1   r2   "validate_console_chunk_max_seconds  r(  z+Settings.validate_console_chunk_max_secondsc                 C  r  )zdValidate the Python executable path.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_x_executable"  r!  zSettings.validate_x_executablec                 C     t |tr
t|S |S rU   r  r+   jsonloadsr  r1   r1   r2   validate_x_extra_http_headers.  s   

z&Settings.validate_x_extra_http_headersc                 C  s   |dur|dk rt d|S )z|Validate the maximum line length for filestream JSONL files.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nr$   z1File stream max line bytes must be greater than 0r&  r  r1   r1   r2   #validate_file_stream_max_line_bytes5  s   z,Settings.validate_file_stream_max_line_bytesc                 C  r  )z]Validate the files directory.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_x_files_dir@  r!  zSettings.validate_x_files_dirc                 C  sN   |  |}t|dr|j}n|}|r%|ddur%|d|jkr%td|S )z]Validate the fork_from field.

        <!-- lazydoc-ignore-classmethod: internal -->
        datar   NzProvided `run_id` is the same as the run to `fork_from`. Please provide a different `run_id` or remove the `run_id` argument. If you want to rewind the current run, please use `resume_from` instead._runmoment_preprocessorhasattrr2  r  runr   r   r	  r   
run_momentr1   r1   r2   validate_fork_fromL  s   

zSettings.validate_fork_fromc                 C      |du rdS t | |dS )zXValidate the HTTP proxy.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nr   r#   r  r  r  r1   r1   r2   validate_http_proxyh     

zSettings.validate_http_proxyc                 C  r:  )zYValidate the HTTPS proxy.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nr   r;  r  r1   r1   r2   validate_https_proxyt  r=  zSettings.validate_https_proxyc                 C  s   t |ts	t|S |S )zZValidate the ignore globs.

        <!-- lazydoc-ignore-classmethod: internal -->
        )r  tupler  r1   r1   r2   validate_ignore_globs  s   zSettings.validate_ignore_globsc                 C  r  )zZValidate the program path.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_program  r!  zSettings.validate_programc                 C  r  )zcValidate the absolute program path.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_program_abspath  r!  z!Settings.validate_program_abspathc                 C  r  )zcValidate the relative program path.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_program_relpath  r!  z!Settings.validate_program_relpathc              	     sp    du rdS t d}t dkrtd d fdd|D }|r6td dd	|d
d	| S )zZValidate the project name.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nz/\#?%:   zInvalid project name z: exceeded 128 charactersc                   s   h | ]}| v r|qS r1   r1   r   charr	  r1   r2   	<setcomp>      z,Settings.validate_project.<locals>.<setcomp>z: cannot contain characters ,z, found )listr  r   r0   )r   r	  r   invalid_chars_listinvalid_charsr1   rG  r2   validate_project  s   zSettings.validate_projectc                 C  s   |du rdS |du rdS |S )z]Validate the resume behavior.

        <!-- lazydoc-ignore-classmethod: internal -->
        FNTrO   r1   r  r1   r1   r2   validate_resume  s
   zSettings.validate_resumec                 C  sN   |  |}t|dr|j}n|}|r%|ddur%|d|jkr%td|S )z_Validate the resume_from field.

        <!-- lazydoc-ignore-classmethod: internal -->
        r2  r   NzGBoth `run_id` and `resume_from` have been specified with different ids.r3  r7  r1   r1   r2   validate_resume_from  s   

zSettings.validate_resume_fromc                 C  r  )z\Validate the root directory.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_root_dir  r!  zSettings.validate_root_dirc                   s|   |du rdS t |dkrtdt |t | krtdt| s(tdd t fdd|D r<td	  |S )
zTValidate the run ID.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nr   zRun ID cannot be emptyz*Run ID cannot start or end with whitespacez%Run ID cannot contain only whitespacez:;,#?/'c                 3  s    | ]}| v V  qd S rU   r1   rE  reserved_charsr1   r2   r     s    z+Settings.validate_run_id.<locals>.<genexpr>z&Run ID cannot contain the characters: )r  r   r  rC   anyr#  r1   rR  r2   validate_run_id  s   zSettings.validate_run_idc                 C  s,   |du rdS t |tjrtt|S t|S )zgValidate the system settings file path.

        <!-- lazydoc-ignore-classmethod: internal -->
        N)r  r  r  r+   r3   r  r1   r1   r2   validate_settings_system  s
   z!Settings.validate_settings_systemc                 C  r%  )z_Validate the service wait time.

        <!-- lazydoc-ignore-classmethod: internal -->
        r   z$Service wait time cannot be negativer   r  r1   r1   r2   validate_service_wait     zSettings.validate_service_waitc                 C  s   |du r|S t jddd |S )zkValidate the start method for subprocesses.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nz`start_method` is deprecated and will be removed in a future version of wandb. This setting is currently non-functional and safely ignored.Fr  )r  r  r  r1   r1   r2   validate_start_method%  s   zSettings.validate_start_methodc                 C  s   t | |dS )Nr   r;  r  r1   r1   r2   ,validate_x_stats_coreweave_metadata_base_url5  s   

z5Settings.validate_x_stats_coreweave_metadata_base_urlc                 C  r+  )z\Validate the GPU device IDs.

        <!-- lazydoc-ignore-classmethod: internal -->
        r,  r  r1   r1   r2   validate_x_stats_gpu_device_ids;     

z(Settings.validate_x_stats_gpu_device_idsc                 C  r  )ztValidate the path to the neuron-monitor config file.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   +validate_x_stats_neuron_monitor_config_pathF  r!  z4Settings.validate_x_stats_neuron_monitor_config_pathc                 C  r+  )zcValidate the OpenMetrics endpoints.

        <!-- lazydoc-ignore-classmethod: internal -->
        r,  r  r1   r1   r2   %validate_stats_open_metrics_endpointsR  r\  z.Settings.validate_stats_open_metrics_endpointsc                 C  r+  )zaValidate the OpenMetrics filters.

        <!-- lazydoc-ignore-classmethod: internal -->
        r,  r  r1   r1   r2   #validate_stats_open_metrics_filters]  r\  z,Settings.validate_stats_open_metrics_filtersc                 C  r+  )zfValidate the OpenMetrics HTTP headers.

        <!-- lazydoc-ignore-classmethod: internal -->
        r,  r  r1   r1   r2   (validate_stats_open_metrics_http_headersh  r\  z1Settings.validate_stats_open_metrics_http_headersc                 C  r%  )zeValidate the stats sampling interval.

        <!-- lazydoc-ignore-classmethod: internal -->
        g?z7Stats sampling interval cannot be less than 0.1 secondsr   r  r1   r1   r2    validate_stats_sampling_intervals  rX  z)Settings.validate_stats_sampling_intervalc                 C  sT   |du rdS t |dkrtdt |t | krtdt| s(td|S )zVValidate the sweep ID.

        <!-- lazydoc-ignore-classmethod: internal -->
        Nr   zSweep ID cannot be emptyz,Sweep ID cannot start or end with whitespacez'Sweep ID cannot contain only whitespace)r  r   r  rC   r  r1   r1   r2   validate_sweep_id~  s   zSettings.validate_sweep_idc                 C  s   |du rdS t |tr|f}nt|}g }t|D ]C\}}t|}t|dkr1|d| d qt|dkr\t|dkrL|dd  d|d	d  n|}|d
| dt| d q|rftd||S )a  Validate run tags.

        Validates that each tag:
        - Is between 1 and 64 characters in length (inclusive)
        - Converts single string values to tuple format
        - Preserves None values

        <!-- lazydoc-ignore-classmethod: internal -->

        Args:
            value: A string, list, tuple, or None representing tags

        Returns:
            tuple: A tuple of validated tags, or None

        Raises:
            ValueError: If any tag is empty or exceeds 64 characters
        Nr   zTag at index z3 is empty. Tags must be between 1 and 64 characters@   +      z...izTag 'z' is z5 characters. Tags must be between 1 and 64 charactersz; )r  r+   r?  	enumerater  appendr   r0   )r   r	  tagserrorsitagtag_strdisplay_tagr1   r1   r2   validate_run_tags  s0   

zSettings.validate_run_tagsc                 C  r  )zbValidate the sweep parameter path.

        <!-- lazydoc-ignore-classmethod: internal -->
        r  r  r1   r1   r2   validate_sweep_param_path  r!  z"Settings.validate_sweep_param_path	List[str]c                 C  s   | j s
tjdd  S g S )Nr$   )_jupytersysargvr   r1   r1   r2   _args  s   zSettings._argsc                 C  s&   ddl m} | }| pt|d  S )z0Check if we are running in a lambda environment.r   )get_lambda_bootstraphandle_event_request)"sentry_sdk.integrations.aws_lambdaru  r5  )r   ru  lambda_bootstrapr1   r1   r2   _aws_lambda  s
   
zSettings._aws_lambdac                 C  s   | j r	| | j S dS )aT  The relative path from the current working directory to the code path.

        For example, if the code path is /home/user/project/example.py, and the
        current working directory is /home/user/project, then the code path local
        is example.py.

        If couldn't find the relative path, this will be an empty string.
        N)r|   _get_program_relpathr   r1   r1   r2   _code_path_local  s   zSettings._code_path_localc                 C  s
   dt jv S )Nzgoogle.colab)rr  modulesr   r1   r1   r2   _colab     
zSettings._colabc                 C     t  S rU   )r'   
in_ipythonr   r1   r1   r2   _ipython     zSettings._ipythonc                 C  r  rU   )r'   
in_jupyterr   r1   r1   r2   rq     r  zSettings._jupyterc                 C  r  rU   )r   _is_likely_kaggler   r1   r1   r2   _kaggle  r  zSettings._kagglec                 C  
   | j dkS )Ndisabledr   r   r1   r1   r2   _noop
  r~  zSettings._noopc                 C  s   | j p| jp| jp| jS rU   )r  rq  r}  r  r   r1   r1   r2   	_notebook  s   zSettings._notebookc                 C  s
   | j dv S )N)offlinedryrunr   r   r1   r1   r2   r    r~  zSettings._offlinec                 C  s   t j ddS )z7The operating system of the machine running the script.T)aliased)r   r   r1   r1   r2   _os     zSettings._osc                 C  s   t   dt    S )N-)r   r   machinelowerr   r1   r1   r2   	_platform  s   zSettings._platformc                 C  s   t   dt   S )N )r   python_implementationpython_versionr   r1   r1   r2   _python$  s   zSettings._pythonc                 C  r  )zWhether we are in shared mode.

        In "shared" mode, multiple processes can write to the same run,
        for example from different machines.
        sharedr   r   r1   r1   r2   _shared)  s   
zSettings._sharedc                 C  s$   | j d u rdS t| j }|dS )Nr   z%Y%m%d_%H%M%S)r   r   fromtimestampstrftime)r   datetime_nowr1   r1   r2   _start_datetime3  s   

zSettings._start_datetimec                 C  s   t | jddS )Ntmpcoder3   sync_dirr   r1   r1   r2   _tmp_code_dir;     zSettings._tmp_code_dirc                 C  s   t  dkS r   r   r   r1   r1   r2   _windows@  s   zSettings._windowsc                 C  s   | j pt| jS )zThe URL for the W&B UI, usually https://wandb.ai.

        This is different from `base_url` (like https://api.wandb.ai) which
        is used to access W&B APIs programmatically.
        )r5   r   api_to_app_urlrL   r   r1   r1   r2   app_urlE  s   zSettings.app_urlc                 C  s2   | j sdS | jr| jdrt| j}d| S dS )z3The URL to the Colab notebook, if running in Colab.NfileId=z+https://colab.research.google.com/notebook#)r}  r   r   r   )r   	unescapedr1   r1   r2   	colab_urlO  s   
zSettings.colab_urlLiteral['local', 'cloud']c                 C  s   | j rdS dS )Nlocalcloud)is_localr   r1   r1   r2   
deploymentZ  r  zSettings.deploymentc                 C  s   | j pt| jdS )zFAbsolute path to the local directory where the run's files are stored.files)r:   r3   r  r   r1   r1   r2   r6   _  s   zSettings.files_dirc                 C  s   t | jdkS )NrK   )r+   rL   r   r1   r1   r2   r  f  r  zSettings.is_localc                 C     t | jdS )z$The directory for storing log files.logsr  r   r1   r1   r2   log_dirk  r  zSettings.log_dirc                 C  r  )z.The path to the file to use for internal logs.debug-internal.logr3   r  r   r1   r1   r2   log_internalq  r  zSettings.log_internalc                 C  r  )zHThe path to the symlink to the internal log file of the most recent run.r  r3   	wandb_dirr   r1   r1   r2   log_symlink_internalw  r  zSettings.log_symlink_internalc                 C  r  )zLThe path to the symlink to the user-process log file of the most recent run.	debug.logr  r   r1   r1   r2   log_symlink_user}  r  zSettings.log_symlink_userc                 C  r  )z2The path to the file to use for user-process logs.r  r  r   r1   r1   r2   log_user  r  zSettings.log_userc                 C  s   |   }|sdS |S )z,The W&B URL where the project can be viewed.r   )_project_url_baser   project_urlr1   r1   r2   r    s   zSettings.project_urlc                 C  r  )zThe path to the resume file.zwandb-resume.jsonr  r   r1   r1   r2   resume_fname  r  zSettings.resume_fnameLiteral['run', 'offline-run']c                 C  s   | j sdS dS )z:The mode of the run. Can be either "run" or "offline-run".r6  zoffline-run)r  r   r1   r1   r2   run_mode  s   zSettings.run_modec                 C  s:   |   }t|| jgsdS d}| dt| jpd|d S )z(The W&B URL where the run can be viewed.r   z=+&$@z/runs/)safe)r  allr   r   )r   r  
safe_charsr1   r1   r2   run_url  s
   zSettings.run_urlc                 C  r  )z(The path to the workspace settings file.settingsr  r   r1   r1   r2   settings_workspace  r  zSettings.settings_workspacec                 C  s2   |   }t|| jgsdS | dt| jpd S )z*The W&B URL where the sweep can be viewed.r   z/sweeps/)r  r  r   r   r  r1   r1   r2   	sweep_url  s   zSettings.sweep_urlc                 C  s<   | j  d| j d| j }| jr|d| j 7 }t| j|S )z*The directory for storing the run's files.r  )r  timespecr   r;   r3   r  )r   namer1   r1   r2   r    s   zSettings.sync_dirc                 C  s   t | jd| j dS )z4Path to the append-only binary transaction log file.zrun-.wandb)r3   r  r   r   r1   r1   r2   	sync_file  s   zSettings.sync_filec                 C  r  )zBPath to the symlink to the most recent run's transaction log file.z
latest-runr  r   r1   r1   r2   sync_symlink_latest  r  zSettings.sync_symlink_latestc                 C  s   | j S )z#The time specification for the run.)r  r   r1   r1   r2   r    s   zSettings.timespecc                 C  sF   | j du rt| jd }n| j }|rdnd}tt| j| S )z!Full path to the wandb directory.Nr  r  )r   r  r  r   existsr+   r/   )r   use_dotdirnamer1   r1   r2   r    s
   
zSettings.wandb_dirsettings_file.SettingsFilesc                 C  s2   t | j}| jrt | j}nd}tj||dS )ag  Read settings from the workspace and global settings files.

        The files are determined by the settings_system and settings_workspace
        settings.

        The resulting object is a snapshot of the system settings at the time
        this function is used and does not reflect the settings on this Settings
        object. It can be used to update the files, and it should be short-lived
        since it does not reflect external changes to the files.

        Updating the settings files does not update this Settings instance
        and vice versa.

        <!-- lazydoc-ignore: internal -->
        N)global_settingslocal_settings)r  r  r  r   r"   SettingsFiles)r   r  r  r1   r1   r2   read_system_settings  s   zSettings.read_system_settingsNonec              
   C  s  |   }t|jdkrdS t|jdkrt|jd }ndddd |jD  }| js7d}td|  nd	}zt|}W n< t	y{ } z0|sQt
d
|  t|tr^t
t| ntt|||j}t
d| W Y d}~dS d}~ww | | dS )zLoad settings from the settings files.

        If settings files contain invalid settings, prints and suppresses
        the error.

        <!-- lazydoc-ignore: internal -->
        r   Nr$   
c                 s  s    | ]}d | V  qdS )z  Nr1   )r   sourcer1   r1   r2   r     s    

z7Settings.update_from_system_settings.<locals>.<genexpr>TzLoading settings from FzFailed to load settings from r   )r  r  sourcesr+   r0   r   r  termlog_parse_system_settings	Exception	termerrorr  r   	tracebackformat_exceptiontype__traceback__update_from_settings)r   system_settingssource_stringprinted_sourcesparsed_settingsetbr1   r1   r2   update_from_system_settings  s2   

z$Settings.update_from_system_settingsenvironDict[str, Any]c                 C  s   d}|d }t jdddt jdt jdt jdt jd	t jd
t jdt jdt j	di
}|
 D ]I\}}||s3q)||v r<|| }n||rNd|t|d   }n
|t|d  }|| jvr^q)|dv rg|d}|du rlq)t| || q)dS )z_Update settings from environment variables.

        <!-- lazydoc-ignore: internal -->
        WANDB_r   r5   WANDB_SERVICE_TRANSPORTr   r   r   r   r   r   r   r   r^   x_N)ro   r   rJ  )r   APP_URLDIRNAMENOTESTAGSJOB_TYPEHTTP_TIMEOUTFILE_PUSHER_TIMEOUT
USER_EMAILitemsr   r  r  __dict__splitsetattr)r   r  
env_prefixprivate_env_prefixspecial_env_var_namessettingr	  r   r1   r1   r2   update_from_env_vars;  s:   




zSettings.update_from_env_varsc                 C  s  | j du s
| j du rttjdusttjdurt | _ ttjdur,t | _| j	rS| j
du s9| j
dkrStj| j}|d| _|d| _|d| _n*| j	rp| j
durptj| j
rp| j
| _| j
| _t | _n| j	r}td| j
 d | jdu rt | _| jptjtjptjpt d	pd	}|| _| j!du rt"t#$ | _!| j%rdS | j&p| ' }|dur| (| nd
}|| _&dS )z`Update settings from the system environment.

        <!-- lazydoc-ignore: internal -->
        TNr   r.   r  rootzGWANDB_NOTEBOOK_NAME should be a path to a notebook file, couldn't find .python3z<python with no main file>))r   r-   getenvr   	SAVE_CODEDISABLE_CODEshould_save_codeDISABLE_GITr[   rq  r{   r  jupyternotebook_metadatar   r  r   r   r   r.   r  r   r  rk   socketgethostnamer   r  _EXECUTABLErr  
executableshutilwhichr]   
get_dockerr   image_id_from_k8sr   r|   _get_program_setup_code_paths)r   meta_executabler|   r1   r1   r2   update_from_system_environmentf  s\   






z'Settings.update_from_system_environmentr  c                 C  s.   t | D ]\}}|durt| || qdS )zVUpdate settings from a dictionary.

        <!-- lazydoc-ignore: internal -->
        N)dictr  r  )r   r  r   r	  r1   r1   r2   update_from_dict  s
   zSettings.update_from_dictc                   s*    fdd j D }|r| | dS dS )zhUpdate settings from another instance of `Settings`.

        <!-- lazydoc-ignore: internal -->
        c                   s   i | ]}|t  |qS r1   )getattr)r   fieldr  r1   r2   
<dictcomp>  rI  z1Settings.update_from_settings.<locals>.<dictcomp>N)model_fields_setr  )r   r  dr1   r  r2   r    s   zSettings.update_from_settingswandb_settings_pb2.Settingsc                 C  s*  t  }| jdd D ]\}}|tv rq|dkrbt|tttfr/t	||}|j
j| n2t|trUt	||}| D ]\}}| D ]\}}||jj| j|< qEq=ntdt| d| q|dv rt|trm|nt|d|d|d	d
}	t	||t j|	j|	j|	jd
 qt|trt	||t|d qt|trt	||t|d qt|trt	||t|d qt|trt	||t|d qt|tttfrt	||}
|
j| qt|trt	||}| D ]	\}}||j|< qq|du rqtdt| d| |S )zgGenerate a protobuf representation of the settings.

        <!-- lazydoc-ignore: internal -->
        T)exclude_noner   zUnsupported type z for setting )rc   r   r6  r	  metric)r6  r	  r!  rG  N)r    r<   
model_dumpr  CLIENT_ONLY_SETTINGSr  rK  setr?  r  sequencer	  extendr  mapping	TypeErrorr  r(   r  CopyFromr6  r!  rC   r   rR   r   rp   r   r+   r   )r   settings_protokvr  r   r	  kkvvr8  r%  r'  r1   r1   r2   to_proto  sl   



	






zSettings.to_protoc                 C  s   | j r| jr	| jS | js| jS | jdr| jS | jS ttj	}|dur'|S zddl
}W n
 ty7   Y dS w z|jdu rD|j}W |S d|jj }W |S  tyW   Y dS w )z1Get the program that started the current process.r  Nr   z-m )rq  r{   r   r|   r   r   r-   r  r   PROGRAM__main__ImportError__spec____file__r  AttributeError)r   r|   r1  python_argsr1   r1   r2   r    s2   
zSettings._get_programr   c                 C  s   | sdS |p	t  }|sdS tt|t| sdS t j|t jt  || }t j	|rAt jj||d}d|v r?dS |S dS )z=Get the relative path to the program from the root directory.N)startz../)
r-   r   r&   are_paths_on_same_driver  r  r.   r0   relpathr  )r|   r   full_path_to_programrelative_pathr1   r1   r2   rz  %  s$   zSettings._get_program_relpathc                 C  s>   t | j| jgs
dS | j dt| jpd dt| jpd S )z'Construct the base URL for the project.r   r   )r  r_   r   r  r   r   r1   r1   r2   r  A  s   *zSettings._project_url_basevalUnion[RunMoment, str, None]c                 C  s.   t | ts	| du r| S t | trt| S dS )z5Preprocess the setting for forking or resuming a run.N)r  r(   r+   from_uri)r<  r1   r1   r2   r4  H  s
   

z Settings._runmoment_preprocessorc                 O  s   | j |i |S rU   )copy)r   r*   kwargsr1   r1   r2   
model_copyT  s   zSettings.model_copyc           	      K  s   | dd}| jdi |}t| jD ]5}t| j|d}t|tr:zt| |}|||< W q ttt	t
fy9   Y qw t|trHt| |}|||< qh d}|D ]	}||v rX||= qO|rddd | D S |S )a  Compatibility method for Pydantic v1 to mimic v2's model_dump.

            In v1, this is equivalent to dict() but also includes computed properties.

            Args:
                **kwargs: Options passed to the dict method
                    - exclude_none: Whether to exclude fields with None values

            Returns:
                A dictionary of the model's fields and computed properties
            r   FN>   
__fields__model_configmodel_fieldsr  __pydantic_self____model_fields_set__pydantic_initialised__c                 S  s   i | ]\}}|d ur||qS rU   r1   )r   r+  r,  r1   r1   r2   r    s    z'Settings.model_dump.<locals>.<dictcomp>r1   )popr  dir	__class__r  r  propertyr5  NotImplementedErrorr(  r   r(   r  )	r   r@  r   resultr  attrr	  exclude_fieldsr  r1   r1   r2   r"  W  s.   



zSettings.model_dumpr$  c                 C  s   t | dt S )zReturn a set of fields that have been explicitly set.

            This is a compatibility property for Pydantic v1 to mimic v2's model_fields_set.
            __fields_set__)r  r$  r   r1   r1   r2   r    s   zSettings.model_fields_setc                 C  s(   | j r| jr| | dS | | dS )z6Sets the program_abspath and program_relpath settings.N)rq  r   _infer_code_paths_for_jupyter_infer_code_path_for_programr   r|   r1   r1   r2   r    s   zSettings._setup_code_pathsc              	   C  s   ddl m} z| js| jpt nt }W n ty$   t }Y nw | jp-| ||| _tj	
tj	|tj	t ||}tj	|rM|| _dS dS )z0Finds the program's absolute and relative paths.r$   )GitRepoN)
lib.gitlibrT  r[   r   r-   r   r  r~   rz  r.   r   r0   r9  r  r}   )r   r|   rT  r   r}   r1   r1   r2   rR    s$    

z%Settings._infer_code_path_for_programc                 C  s2   | j r|sdS tjtj| j || _|| _dS )zFind the notebook's absolute and relative paths.

        Since the notebook's execution environment
        is not the same as the current working directory.
        We utilize the metadata provided by the jupyter server.
        N)r   r-   r.   r   r0   r}   r~   rS  r1   r1   r2   rQ    s   

z&Settings._infer_code_paths_for_jupyter)r,   r   )r	  r
  r,   r
  )r,   rb   )r,   rp  )r,   rC   )r,   rH   )r,   r+   )r,   r  )r,   r  )r,   r  )r,   r  )r  r  )r  r  r,   r  )r  r<   r,   r  )r,   r  rU   )r|   r+   r   rH   r,   rH   )r<  r=  r,   rb   )r,   r$  )r|   r+   (  __name__
__module____qualname____doc__r   rC  rD   __annotations__rE   r   r!   r  r4   rI   rJ   r5   rL   rM   rN   rP   rQ   rS   rT   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rc   rd   rf   rg   rh   rj   rk   rl   rm   rn   ro   rq   rr   rs   rt   ru   rv   rw   rx   rz   r{   r|   r}   r~   r   r   r9   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   loggingINFOr   r   r   r   r   r   r   r   r   r   r   r   r   r-   getpidr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r   r   classmethodr   r   r  r  r)   r   r  r  r  r   r$  r'  r)  r*  r/  r0  r1  r9  r<  r>  r@  rA  rB  rC  rN  rO  rP  rQ  rU  rV  rW  rY  rZ  r[  r]  r^  r_  r`  ra  rb  rn  ro  r   rK  rt  ry  r{  r}  r  rq  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r6   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/  r  staticmethodrz  r  r4  rA  r"  r  r  rR  rQ  r1   r1   r1   r2   r<   B   sx  
 			

	
	





	












	





















	


	


	
	
	
	

5	
	4+B	E$	7r<   T)validate_assignmentr  r  c                 C  s   t  }|   D ]5\}}|dkr|d||< q	|dkr*tjddd tj||< q	|dv r:td|d	d
  q	|||< q	tdi |S )zValidate settings from a settings file.

    Returns:
        A validated Settings object.

    Raises:
        ValidationError: on invalid data.
        Exception: arbitrary errors can occur when constructing Settings.
    ro   rJ  r4   zDeprecated setting 'anonymous' has no effect and will be removed in a future version of wandb. Please delete it manually or by running `wandb login` to avoid errors.Fr  )r   r   zIgnoring setting z) which is not allowed in a settings file.z9 Please delete it manually to avoid errors in the future.Nr1   )	r  r  r  r  r  r  r!   r  r<   )r  fieldsr   r	  r1   r1   r2   r    s$   

r  )r*   r+   r,   r+   )r  r  r,   r<   )B
__future__r   r-  r[  r-   r  r   r  r  r
  rr  r  collections.abcr   r   typingr   r   r   r   r	   r
   r   urllib.parser   r   google.protobuf.wrappers_pb2r   r   r   r   pydanticr   r   r   typing_extensionsr   r  r   r   wandb._pydanticr   r   r   r   r   r   wandb.errorsr   wandb.protor    wandb.sdk.libr!   r"   r#   libr%   r&   r'   lib.run_momentr(   r)   r3   r#  r<   r  r1   r1   r1   r2   <module>   sd    $ 

                 