
import functools
import math

import flax.linen as nn
import jax
import jax.numpy as jnp
def     UpperCAmelCase__							(       __magic_name__						:     List[str]							,  __magic_name__						:     Any							,  __magic_name__						:     List[str]							,  __magic_name__						:     Tuple							,  __magic_name__						:     int = 40_96  ):


					'''simple docstring'''

					lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					int  	=     key.shape[-3:]
					lowerCAmelCase		:					int  	=     value.shape[-1]
					lowerCAmelCase		:					str  	=     min(__magic_name__							,  __magic_name__  )
					lowerCAmelCase		:					Optional[Any]  	=     query / jnp.sqrt(__magic_name__  )

					@functools.partial(jax.checkpoint							,  prevent_cse=__magic_name__  )
					def summarize_chunk(__magic_name__						:     List[Any]							,  __magic_name__						:     Tuple							,  __magic_name__						:     List[str]  ):
										lowerCAmelCase		:					Dict  	=     jnp.einsum('''...qhd,...khd->...qhk'''							,  __magic_name__							,  __magic_name__							,  precision=__magic_name__  )

										lowerCAmelCase		:					Optional[int]  	=     jnp.max(__magic_name__							,  axis=-1							,  keepdims=__magic_name__  )
										lowerCAmelCase		:					Any  	=     jax.lax.stop_gradient(__magic_name__  )
										lowerCAmelCase		:					int  	=     jnp.exp(attn_weights - max_score  )

										lowerCAmelCase		:					List[str]  	=     jnp.einsum('''...vhf,...qhv->...qhf'''							,  __magic_name__							,  __magic_name__							,  precision=__magic_name__  )
										lowerCAmelCase		:					List[Any]  	=     jnp.einsum('''...qhk->...qh'''							,  __magic_name__  )

										return (exp_values, exp_weights.sum(axis=-1  ), max_score)

					def chunk_scanner(__magic_name__						:     Any  ):
										# julienne key array
										lowerCAmelCase		:					str  	=     jax.lax.dynamic_slice(
										    operand=__magic_name__							,  start_indices=[0] * (key.ndim - 3) + [chunk_idx, 0, 0]							,  slice_sizes=list(key.shape[:-3]  ) + [key_chunk_size, num_heads, k_features]							,  )

										# julienne value array
										lowerCAmelCase		:					Union[str, Any]  	=     jax.lax.dynamic_slice(
										    operand=__magic_name__							,  start_indices=[0] * (value.ndim - 3) + [chunk_idx, 0, 0]							,  slice_sizes=list(value.shape[:-3]  ) + [key_chunk_size, num_heads, v_features]							,  )

										return summarize_chunk(__magic_name__							,  __magic_name__							,  __magic_name__  )

					lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					Dict  	=     jax.lax.map(f=__magic_name__							,  xs=jnp.arange(0							,  __magic_name__							,  __magic_name__  )  )

					lowerCAmelCase		:					Optional[Any]  	=     jnp.max(__magic_name__							,  axis=0							,  keepdims=__magic_name__  )
					lowerCAmelCase		:					Union[str, Any]  	=     jnp.exp(chunk_max - global_max  )

					chunk_values *= jnp.expand_dims(__magic_name__							,  axis=-1  )
					chunk_weights *= max_diffs

					lowerCAmelCase		:					Any  	=     chunk_values.sum(axis=0  )
					lowerCAmelCase		:					int  	=     jnp.expand_dims(__magic_name__							,  -1  ).sum(axis=0  )

					return all_values / all_weights
def     UpperCAmelCase__							(       __magic_name__						:     Tuple							,  __magic_name__						:     Optional[int]							,  __magic_name__						:     Dict							,  __magic_name__						:     Optional[int]=jax.lax.Precision.HIGHEST							,  __magic_name__						:     int = 10_24							,  __magic_name__						:     int = 40_96  ):


					'''simple docstring'''

					lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					Optional[int]  	=     query.shape[-3:]

					def chunk_scanner(__magic_name__						:     Tuple							,  __magic_name__						:     Any  ):
										# julienne query array
										lowerCAmelCase		:					Any  	=     jax.lax.dynamic_slice(
										    operand=__magic_name__							,  start_indices=([0] * (query.ndim - 3)) + [chunk_idx, 0, 0]							,  slice_sizes=list(query.shape[:-3]  ) + [min(__magic_name__							,  __magic_name__  ), num_heads, q_features]							,  )

										return (
										    chunk_idx + query_chunk_size,  # unused ignore it
										    _query_chunk_attention(
										        query=__magic_name__							,  key=__magic_name__							,  value=__magic_name__							,  precision=__magic_name__							,  key_chunk_size=__magic_name__  ),
										)

					lowerCAmelCase	,							lowerCAmelCase		:					Union[str, Any]  	=     jax.lax.scan(
					    f=__magic_name__							,  init=0							,  xs=__magic_name__							,  length=math.ceil(num_q / query_chunk_size  )  )

					return jnp.concatenate(__magic_name__							,  axis=-3  )  # fuse the chunked result back


class 		__magic_name__   (						nn.Module    ):
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	8
		_lowerCAmelCase		=	64
		_lowerCAmelCase		=	0.0
		_lowerCAmelCase		=	False
		_lowerCAmelCase		=	jnp.floataa





		def       _A							(							self    :	Tuple				):
							lowerCAmelCase		:					List[Any]  	=     self.dim_head * self.heads
							lowerCAmelCase		:					List[Any]  	=     self.dim_head**-0.5

							# Weights were exported with old names {to_q, to_k, to_v, to_out}
							lowerCAmelCase		:					int  	=     nn.Dense(lowerCamelCase__						,  use_bias=lowerCamelCase__						,  dtype=self.dtype						,  name='''to_q'''				)
							lowerCAmelCase		:					Dict  	=     nn.Dense(lowerCamelCase__						,  use_bias=lowerCamelCase__						,  dtype=self.dtype						,  name='''to_k'''				)
							lowerCAmelCase		:					List[str]  	=     nn.Dense(lowerCamelCase__						,  use_bias=lowerCamelCase__						,  dtype=self.dtype						,  name='''to_v'''				)

							lowerCAmelCase		:					Any  	=     nn.Dense(self.query_dim						,  dtype=self.dtype						,  name='''to_out_0'''				)
							lowerCAmelCase		:					int  	=     nn.Dropout(rate=self.dropout				)





		def       _A							(							self    :	Dict						,  lowerCamelCase__    :	Any				):
							lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					int  	=     tensor.shape
							lowerCAmelCase		:					Any  	=     self.heads
							lowerCAmelCase		:					Tuple  	=     tensor.reshape(lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__						,  dim // head_size				)
							lowerCAmelCase		:					Union[str, Any]  	=     jnp.transpose(lowerCamelCase__						,  (0, 2, 1, 3)				)
							lowerCAmelCase		:					Any  	=     tensor.reshape(batch_size * head_size						,  lowerCamelCase__						,  dim // head_size				)
							return tensor





		def       _A							(							self    :	Any						,  lowerCamelCase__    :	Any				):
							lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					int  	=     tensor.shape
							lowerCAmelCase		:					Dict  	=     self.heads
							lowerCAmelCase		:					Optional[Any]  	=     tensor.reshape(batch_size // head_size						,  lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__				)
							lowerCAmelCase		:					List[Any]  	=     jnp.transpose(lowerCamelCase__						,  (0, 2, 1, 3)				)
							lowerCAmelCase		:					Optional[Any]  	=     tensor.reshape(batch_size // head_size						,  lowerCamelCase__						,  dim * head_size				)
							return tensor





		def __call__(							self    :	Optional[Any]						,  lowerCamelCase__    :	Any						,  lowerCamelCase__    :	Union[str, Any]=None						,  lowerCamelCase__    :	Tuple=True				):
							lowerCAmelCase		:					Tuple  	=     hidden_states if context is None else context

							lowerCAmelCase		:					int  	=     self.query(lowerCamelCase__				)
							lowerCAmelCase		:					str  	=     self.key(lowerCamelCase__				)
							lowerCAmelCase		:					Tuple  	=     self.value(lowerCamelCase__				)

							lowerCAmelCase		:					Any  	=     self.reshape_heads_to_batch_dim(lowerCamelCase__				)
							lowerCAmelCase		:					List[str]  	=     self.reshape_heads_to_batch_dim(lowerCamelCase__				)
							lowerCAmelCase		:					str  	=     self.reshape_heads_to_batch_dim(lowerCamelCase__				)

							if self.use_memory_efficient_attention:
												lowerCAmelCase		:					Optional[int]  	=     query_states.transpose(1						,  0						,  2				)
												lowerCAmelCase		:					List[str]  	=     key_states.transpose(1						,  0						,  2				)
												lowerCAmelCase		:					List[str]  	=     value_states.transpose(1						,  0						,  2				)

												# this if statement create a chunk size for each layer of the unet
												# the chunk size is equal to the query_length dimension of the deepest layer of the unet

												lowerCAmelCase		:					Union[str, Any]  	=     query_states.shape[-3]
												if flatten_latent_dim % 6_4 == 0:
																	lowerCAmelCase		:					Tuple  	=     int(flatten_latent_dim / 6_4				)
												elif flatten_latent_dim % 1_6 == 0:
																	lowerCAmelCase		:					Tuple  	=     int(flatten_latent_dim / 1_6				)
												elif flatten_latent_dim % 4 == 0:
																	lowerCAmelCase		:					Optional[Any]  	=     int(flatten_latent_dim / 4				)
												else:
																	lowerCAmelCase		:					int  	=     int(lowerCamelCase__				)

												lowerCAmelCase		:					int  	=     jax_memory_efficient_attention(
												    lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__						,  query_chunk_size=lowerCamelCase__						,  key_chunk_size=4_0_9_6 * 4				)

												lowerCAmelCase		:					Union[str, Any]  	=     hidden_states.transpose(1						,  0						,  2				)
							else:
												# compute attentions
												lowerCAmelCase		:					Tuple  	=     jnp.einsum('''b i d, b j d->b i j'''						,  lowerCamelCase__						,  lowerCamelCase__				)
												lowerCAmelCase		:					List[Any]  	=     attention_scores * self.scale
												lowerCAmelCase		:					int  	=     nn.softmax(lowerCamelCase__						,  axis=2				)

												# attend to values
												lowerCAmelCase		:					Optional[Any]  	=     jnp.einsum('''b i j, b j d -> b i d'''						,  lowerCamelCase__						,  lowerCamelCase__				)

							lowerCAmelCase		:					Optional[int]  	=     self.reshape_batch_dim_to_heads(lowerCamelCase__				)
							lowerCAmelCase		:					List[Any]  	=     self.proj_attn(lowerCamelCase__				)
							return self.dropout_layer(lowerCamelCase__						,  deterministic=lowerCamelCase__				)



class 		__magic_name__   (						nn.Module    ):
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	0.0
		_lowerCAmelCase		=	False
		_lowerCAmelCase		=	jnp.floataa
		_lowerCAmelCase		=	False





		def       _A							(							self    :	List[Any]				):
							# self attention (or cross_attention if only_cross_attention is True)
							lowerCAmelCase		:					List[Any]  	=     FlaxAttention(
							    self.dim						,  self.n_heads						,  self.d_head						,  self.dropout						,  self.use_memory_efficient_attention						,  dtype=self.dtype				)
							# cross attention
							lowerCAmelCase		:					str  	=     FlaxAttention(
							    self.dim						,  self.n_heads						,  self.d_head						,  self.dropout						,  self.use_memory_efficient_attention						,  dtype=self.dtype				)
							lowerCAmelCase		:					Tuple  	=     FlaxFeedForward(dim=self.dim						,  dropout=self.dropout						,  dtype=self.dtype				)
							lowerCAmelCase		:					List[Any]  	=     nn.LayerNorm(epsilon=1E-5						,  dtype=self.dtype				)
							lowerCAmelCase		:					Union[str, Any]  	=     nn.LayerNorm(epsilon=1E-5						,  dtype=self.dtype				)
							lowerCAmelCase		:					Dict  	=     nn.LayerNorm(epsilon=1E-5						,  dtype=self.dtype				)
							lowerCAmelCase		:					str  	=     nn.Dropout(rate=self.dropout				)





		def __call__(							self    :	Dict						,  lowerCamelCase__    :	Any						,  lowerCamelCase__    :	Tuple						,  lowerCamelCase__    :	str=True				):
							# self attention
							lowerCAmelCase		:					List[Any]  	=     hidden_states
							if self.only_cross_attention:
												lowerCAmelCase		:					int  	=     self.attna(self.norma(lowerCamelCase__				)						,  lowerCamelCase__						,  deterministic=lowerCamelCase__				)
							else:
												lowerCAmelCase		:					List[Any]  	=     self.attna(self.norma(lowerCamelCase__				)						,  deterministic=lowerCamelCase__				)
							lowerCAmelCase		:					List[Any]  	=     hidden_states + residual

							# cross attention
							lowerCAmelCase		:					str  	=     hidden_states
							lowerCAmelCase		:					Union[str, Any]  	=     self.attna(self.norma(lowerCamelCase__				)						,  lowerCamelCase__						,  deterministic=lowerCamelCase__				)
							lowerCAmelCase		:					Any  	=     hidden_states + residual

							# feed forward
							lowerCAmelCase		:					int  	=     hidden_states
							lowerCAmelCase		:					Union[str, Any]  	=     self.ff(self.norma(lowerCamelCase__				)						,  deterministic=lowerCamelCase__				)
							lowerCAmelCase		:					List[Any]  	=     hidden_states + residual

							return self.dropout_layer(lowerCamelCase__						,  deterministic=lowerCamelCase__				)



class 		__magic_name__   (						nn.Module    ):
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	1
		_lowerCAmelCase		=	0.0
		_lowerCAmelCase		=	False
		_lowerCAmelCase		=	False
		_lowerCAmelCase		=	jnp.floataa
		_lowerCAmelCase		=	False





		def       _A							(							self    :	Optional[Any]				):
							lowerCAmelCase		:					Any  	=     nn.GroupNorm(num_groups=3_2						,  epsilon=1E-5				)

							lowerCAmelCase		:					str  	=     self.n_heads * self.d_head
							if self.use_linear_projection:
												lowerCAmelCase		:					Optional[Any]  	=     nn.Dense(lowerCamelCase__						,  dtype=self.dtype				)
							else:
												lowerCAmelCase		:					str  	=     nn.Conv(
												    lowerCamelCase__						,  kernel_size=(1, 1)						,  strides=(1, 1)						,  padding='''VALID'''						,  dtype=self.dtype						,  )

							lowerCAmelCase		:					Union[str, Any]  	=     [
							    FlaxBasicTransformerBlock(
							        lowerCamelCase__						,  self.n_heads						,  self.d_head						,  dropout=self.dropout						,  only_cross_attention=self.only_cross_attention						,  dtype=self.dtype						,  use_memory_efficient_attention=self.use_memory_efficient_attention						,  )
							    for _ in range(self.depth				)
							]

							if self.use_linear_projection:
												lowerCAmelCase		:					Optional[int]  	=     nn.Dense(lowerCamelCase__						,  dtype=self.dtype				)
							else:
												lowerCAmelCase		:					List[Any]  	=     nn.Conv(
												    lowerCamelCase__						,  kernel_size=(1, 1)						,  strides=(1, 1)						,  padding='''VALID'''						,  dtype=self.dtype						,  )

							lowerCAmelCase		:					int  	=     nn.Dropout(rate=self.dropout				)





		def __call__(							self    :	Union[str, Any]						,  lowerCamelCase__    :	List[Any]						,  lowerCamelCase__    :	List[Any]						,  lowerCamelCase__    :	str=True				):
							lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					Any  	=     hidden_states.shape
							lowerCAmelCase		:					List[Any]  	=     hidden_states
							lowerCAmelCase		:					str  	=     self.norm(lowerCamelCase__				)
							if self.use_linear_projection:
												lowerCAmelCase		:					int  	=     hidden_states.reshape(lowerCamelCase__						,  height * width						,  lowerCamelCase__				)
												lowerCAmelCase		:					Tuple  	=     self.proj_in(lowerCamelCase__				)
							else:
												lowerCAmelCase		:					Union[str, Any]  	=     self.proj_in(lowerCamelCase__				)
												lowerCAmelCase		:					List[Any]  	=     hidden_states.reshape(lowerCamelCase__						,  height * width						,  lowerCamelCase__				)

							for transformer_block in self.transformer_blocks:
												lowerCAmelCase		:					List[str]  	=     transformer_block(lowerCamelCase__						,  lowerCamelCase__						,  deterministic=lowerCamelCase__				)

							if self.use_linear_projection:
												lowerCAmelCase		:					Optional[int]  	=     self.proj_out(lowerCamelCase__				)
												lowerCAmelCase		:					List[Any]  	=     hidden_states.reshape(lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__				)
							else:
												lowerCAmelCase		:					Optional[Any]  	=     hidden_states.reshape(lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__						,  lowerCamelCase__				)
												lowerCAmelCase		:					str  	=     self.proj_out(lowerCamelCase__				)

							lowerCAmelCase		:					Optional[int]  	=     hidden_states + residual
							return self.dropout_layer(lowerCamelCase__						,  deterministic=lowerCamelCase__				)



class 		__magic_name__   (						nn.Module    ):
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	0.0
		_lowerCAmelCase		=	jnp.floataa





		def       _A							(							self    :	int				):
							# The second linear layer needs to be called
							# net_2 for now to match the index of the Sequential layer
							lowerCAmelCase		:					Dict  	=     FlaxGEGLU(self.dim						,  self.dropout						,  self.dtype				)
							lowerCAmelCase		:					List[Any]  	=     nn.Dense(self.dim						,  dtype=self.dtype				)





		def __call__(							self    :	Any						,  lowerCamelCase__    :	Dict						,  lowerCamelCase__    :	Optional[int]=True				):
							lowerCAmelCase		:					str  	=     self.net_a(lowerCamelCase__						,  deterministic=lowerCamelCase__				)
							lowerCAmelCase		:					Any  	=     self.net_a(lowerCamelCase__				)
							return hidden_states



class 		__magic_name__   (						nn.Module    ):
		_lowerCAmelCase		=	42
		_lowerCAmelCase		=	0.0
		_lowerCAmelCase		=	jnp.floataa





		def       _A							(							self    :	int				):
							lowerCAmelCase		:					Union[str, Any]  	=     self.dim * 4
							lowerCAmelCase		:					Any  	=     nn.Dense(inner_dim * 2						,  dtype=self.dtype				)
							lowerCAmelCase		:					Optional[Any]  	=     nn.Dropout(rate=self.dropout				)





		def __call__(							self    :	int						,  lowerCamelCase__    :	Optional[Any]						,  lowerCamelCase__    :	List[Any]=True				):
							lowerCAmelCase		:					Optional[Any]  	=     self.proj(lowerCamelCase__				)
							lowerCAmelCase	,							lowerCAmelCase		:					Any  	=     jnp.split(lowerCamelCase__						,  2						,  axis=2				)
							return self.dropout_layer(hidden_linear * nn.gelu(lowerCamelCase__				)						,  deterministic=lowerCamelCase__				)


import os
from shutil import copyfile
from typing import TYPE_CHECKING, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging
from ...utils.versions import require_version


if TYPE_CHECKING:
		from transformers.pipelines.conversational import Conversation

require_version('tokenizers>=0.13.3')

if is_sentencepiece_available():
		from .tokenization_llama import LlamaTokenizer
else:
		__SCREAMING_SNAKE_CASE			:   int         =     None

__SCREAMING_SNAKE_CASE			:   List[Any]         =     logging.get_logger(__name__)
__SCREAMING_SNAKE_CASE			:   Optional[int]         =     {'vocab_file': 'tokenizer.model', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE			:   Dict         =     '[INST]', '[/INST]'
__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE			:   List[Any]         =     '<<SYS>>\n', '\n<</SYS>>\n\n'

# fmt: off
__SCREAMING_SNAKE_CASE			:   List[Any]         =     'You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your\\nanswers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure\\nthat your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not\\ncorrect. If you don\'t know the answer to a question, please don\'t share false information.'


class 		__magic_name__   (						snake_case    ):
		_lowerCAmelCase		=	VOCAB_FILES_NAMES
		_lowerCAmelCase		=	LlamaTokenizer
		_lowerCAmelCase		=	"left"
		_lowerCAmelCase		=	["input_ids", "attention_mask"]





		def __init__(							self    :	List[Any]						,  lowerCamelCase__    :	int=None						,  lowerCamelCase__    :	Union[str, Any]=None						,  lowerCamelCase__    :	List[str]=False						,  lowerCamelCase__    :	int="<unk>"						,  lowerCamelCase__    :	int="<s>"						,  lowerCamelCase__    :	str="</s>"						,  lowerCamelCase__    :	Optional[Any]=True						,  lowerCamelCase__    :	int=False						,  **lowerCamelCase__    :	List[str]						,  ):
							super().__init__(
							    vocab_file=lowerCamelCase__						,  tokenizer_file=lowerCamelCase__						,  clean_up_tokenization_spaces=lowerCamelCase__						,  unk_token=lowerCamelCase__						,  bos_token=lowerCamelCase__						,  eos_token=lowerCamelCase__						,  **lowerCamelCase__						,  )
							lowerCAmelCase		:					Optional[int]  	=     add_bos_token
							lowerCAmelCase		:					int  	=     add_eos_token
							self.update_post_processor()

							lowerCAmelCase		:					List[Any]  	=     vocab_file
							lowerCAmelCase		:					List[str]  	=     False if not self.vocab_file else True





		def       _A							(							self    :	Tuple				):
							lowerCAmelCase		:					List[str]  	=     self.bos_token
							lowerCAmelCase		:					Optional[Any]  	=     self.bos_token_id

							lowerCAmelCase		:					Optional[Any]  	=     self.eos_token
							lowerCAmelCase		:					List[str]  	=     self.eos_token_id

							lowerCAmelCase		:					Dict  	=     f'''{(bos+":0 ") * self.add_bos_token}$A:0{(" "+eos+":0") * self.add_eos_token}'''
							lowerCAmelCase		:					Optional[int]  	=     f'''{single}{(" "+bos+":1") * self.add_bos_token} $B:1{(" "+eos+":1") * self.add_eos_token}'''

							lowerCAmelCase		:					Any  	=     []
							if self.add_bos_token:
												special_tokens.append((bos, bos_token_id)				)
							if self.add_eos_token:
												special_tokens.append((eos, eos_token_id)				)
							lowerCAmelCase		:					Union[str, Any]  	=     processors.TemplateProcessing(
							    single=lowerCamelCase__						,  pair=lowerCamelCase__						,  special_tokens=lowerCamelCase__				)





		@property
		def       _A							(							self    :	str				):
							return self._add_eos_token





		@property
		def       _A							(							self    :	Dict				):
							return self._add_bos_token





		@add_eos_token.setter
		def       _A							(							self    :	Union[str, Any]						,  lowerCamelCase__    :	str				):
							lowerCAmelCase		:					Any  	=     value
							self.update_post_processor()





		@add_bos_token.setter
		def       _A							(							self    :	Dict						,  lowerCamelCase__    :	Optional[Any]				):
							lowerCAmelCase		:					List[Any]  	=     value
							self.update_post_processor()





		def       _A							(							self    :	int						,  lowerCamelCase__    :	str						,  lowerCamelCase__    :	Optional[str] = None				):
							if not self.can_save_slow_tokenizer:
												raise ValueError(
												    '''Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '''
												    '''tokenizer.'''				)

							if not os.path.isdir(lowerCamelCase__				):
												logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''				)
												return
							lowerCAmelCase		:					str  	=     os.path.join(
							    lowerCamelCase__						,  (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']				)

							if os.path.abspath(self.vocab_file				) != os.path.abspath(lowerCamelCase__				):
												copyfile(self.vocab_file						,  lowerCamelCase__				)

							return (out_vocab_file,)





		def       _A							(							self    :	Any						,  lowerCamelCase__    :	"Conversation"				):
							lowerCAmelCase		:					int  	=     list(conversation.iter_texts()				)
							if not all([is_user for is_user, msg in dialogue[::2]]				) or not all(
							    [not is_user for is_user, msg in dialogue[1::2]]				):
												raise ValueError(
												    '''The model only supports \'user\' and \'assistant\' roles, starting with user and alternating (u/a/u/a/u...)'''				)

							lowerCAmelCase		:					List[str]  	=     []
							if len(conversation.past_user_inputs				) > 0:
												if not conversation.past_user_inputs[0].startswith(lowerCamelCase__				) or E_SYS not in conversation.past_user_inputs[0]:
																	lowerCAmelCase		:					Tuple  	=     (
																	    B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS + conversation.past_user_inputs[0]
																	)
							elif not dialogue[0][1].startswith(lowerCamelCase__				) or E_SYS not in dialogue[0][1]:
												lowerCAmelCase		:					Optional[Any]  	=     (dialogue[0][0], B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS + dialogue[0][1])

							dialog_tokens += sum(
							    [
							        [self.bos_token_id]
							        + self.encode(
							            f'''{B_INST} {(prompt[1]).strip()} {E_INST} {(answer[1]).strip()} '''						,  add_special_tokens=lowerCamelCase__				)
							        + [self.eos_token_id]
							        for prompt, answer in zip(dialogue[::2]						,  dialogue[1::2]				)
							    ]						,  []						,  )
							if not (dialogue[-1][0]):
												raise ValueError(f'''Last message must be from user, got {dialogue[-1]["role"]}'''				)
							dialog_tokens += [self.bos_token_id] + self.encode(
							    f'''{B_INST} {(dialogue[-1][1]).strip()} {E_INST}'''						,  add_special_tokens=lowerCamelCase__				)
							return dialog_tokens
