import transformers from transformers import AutoModelForCausalLM, AutoTokenizer # from optimum.bettertransformer import BetterTransformer from tokenization_yi import YiTokenizer import torch import os import bitsandbytes import gradio as gr import sentencepiece os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:56' MAX_MAX_NEW_TOKENS = 160000 DEFAULT_MAX_NEW_TOKENS = 100000 MAX_INPUT_TOKEN_LENGTH = 50000 DESCRIPTION = """ # Welcome to Tonic's Yi-6B-200K You can use this Space to test out the current model [01-ai/Yi-6B-200K](https://huggingface.co/01-ai/Yi-6B-200K) You can also use YI-200 by cloning this space. Simply click here: Duplicate Space Join us : TeamTonic is always making cool demos! Join our active builder's community on Discord: [Discord](https://discord.gg/nXx5wbX9) On Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On Github: [Polytonic](https://github.com/tonic-ai) & contribute to [PolyGPT](https://github.com/tonic-ai/polygpt-alpha) """ # Set up the model and tokenizer model_name = "01-ai/Yi-6B-200K" device = "cuda" if torch.cuda.is_available() else "cpu" tokenizer = AutoTokenizer.from_pretrained(model_name, device_map="cuda", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained( model_name, device_map="auto", torch_dtype=torch.bfloat16, load_in_4bit=True, trust_remote_code=True ) def run(prompt, max_new_tokens, temperature, top_p, top_k): input_ids = tokenizer.encode(prompt, return_tensors='pt').to(device) response_ids = model.generate( input_ids, max_length=max_new_tokens + input_ids.shape[1], temperature=temperature, top_p=top_p, top_k=top_k, pad_token_id=tokenizer.eos_token_id, do_sample=True ) response = tokenizer.decode(response_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True) return response def generate(prompt, max_new_tokens, temperature, top_p, top_k): response = run(prompt, max_new_tokens, temperature, top_p, top_k) return response # Gradio Interface with gr.Blocks(theme='ParityError/Anime') as demo: gr.Markdown(DESCRIPTION) with gr.Group(): with gr.Row(): prompt = gr.Textbox( label='Enter your prompt', placeholder='Type something...', lines=5 ) with gr.Accordion(label='Advanced options', open=False): max_new_tokens = gr.Slider(label='Max New Tokens', minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS) temperature = gr.Slider(label='Temperature', minimum=0.1, maximum=2.0, step=0.1, value=1.2) top_p = gr.Slider(label='Top-P (nucleus sampling)', minimum=0.05, maximum=1.0, step=0.05, value=0.9) top_k = gr.Slider(label='Top-K', minimum=1, maximum=1000, step=1, value=900) # gr.Examples(visible=False,[["From Wikipedia, the free encyclopedia \\n Photo of Willard Van Orman Quine \\n Willard Quine \\n Photo of Hilary Putnam \\n Hilary Putnam \\n The Quine\u2013Putnam indispensability argument[a] is an argument in the philosophy of mathematics for the existence of abstract mathematical objects such as numbers and sets, a position known as mathematical platonism. It was named after the philosophers Willard Quine and Hilary Putnam, and is one of the most important arguments in the philosophy of mathematics. \\n \\n Although elements of the indispensability argument may have originated with thinkers such as Gottlob Frege and Kurt G\u00F6del, Quine's development of the argument was unique for introducing to it a number of his philosophical positions such as naturalism, confirmational holism, and the criterion of ontological commitment. Putnam gave Quine's argument its first detailed formulation in his 1971 book Philosophy of Logic. He later came to disagree with various aspects of Quine's thinking, however, and formulated his own indispensability argument based on the no miracles argument in the philosophy of science. A standard form of the argument in contemporary philosophy is credited to Mark Colyvan; whilst being influenced by both Quine and Putnam, it differs in important ways from their formulations. It is presented in the Stanford Encyclopedia of Philosophy:[2] \\n \\n We ought to have ontological commitment to all and only the entities that are indispensable to our best scientific theories. \\n Mathematical entities are indispensable to our best scientific theories. \\n Therefore, we ought to have ontological commitment to mathematical entities. \\n Nominalists, philosophers who reject the existence of abstract objects, have argued against both premises of this argument. An influential argument by Hartry Field claims that mathematical entities are dispensable to science. This argument has been supported by attempts to demonstrate that scientific and mathematical theories can be reformulated to remove all references to mathematical entities. Other philosophers, including Penelope Maddy, Elliott Sober, and Joseph Melia, have argued that we do not need to believe in all of the entities that are indispensable to science. The arguments of these writers inspired a new explanatory version of the argument, which Alan Baker and Mark Colyvan support, that argues mathematics is indispensable to specific scientific explanations as well as whole theories. \\n \\n Background \\n In his 1973 paper \"Mathematical Truth\", Paul Benacerraf (1973) raised a problem for the philosophy of mathematics.[b] According to Benacerraf, mathematical sentences such as \"two is a prime number\" seem to imply the existence of mathematical objects.[5] He supported this claim with the idea that mathematics should not have its own special semantics, or in other words, the meaning of mathematical sentences should follow the same rules as non-mathematical sentences. For example, according to this reasoning, if the sentence \"Mars is a planet\" implies the existence of the planet Mars, then the sentence \"two is a prime number\" should also imply the existence of the number two.[6] But according to Benacerraf, if mathematical objects existed, they would be unknowable to us.[5] This is because mathematical objects, if they exist, are abstract objects: objects that cannot cause things to happen and that have no spatio-temporal location.[7] Benacerraf argued, on the basis of the causal theory of knowledge, that we would not be able to know about such objects because they cannot come into causal contact with us.[c][8] This is called Benacerraf's epistemological problem because it concerns the epistemology of mathematics, that is, how we come to know what we do about mathematics.[9] \\n \\n The philosophy of mathematics is split into two main strands: platonism and nominalism. Platonism holds that there exist abstract mathematical objects such as numbers and sets whilst nominalism denies their existence.[10] Each of these views faces issues due to the problem raised by Benacerraf. Because nominalism rejects the existence of mathematical objects, it faces no epistemological problem but it does face problems concerning the idea that mathematics should not have its own special semantics. Platonism does not face problems concerning the semantic half of the dilemma but it has difficulty explaining how we can have any knowledge about mathematical objects.[11] \\n \\n The indispensability argument aims to overcome the epistemological problem posed against platonism by providing a justification for belief in abstract mathematical objects.[5] It is part of a broad class of indispensability arguments most commonly applied in the philosophy of mathematics, but which also includes arguments in the philosophy of language and ethics.[12] In the most general sense, indispensability arguments aim to support their conclusion based on the claim that the truth of the conclusion is indispensable or necessary for a certain purpose.[13] When applied in the field of ontology\u2014the study of what exists\u2014they exemplify a Quinean strategy for establishing the existence of controversial entities that cannot be directly investigated. According to this strategy, the indispensability of these entities for formulating a theory of other less controversial entities counts as evidence for their existence.[14] In the case of philosophy of mathematics, the indispensability of mathematical entities for formulating scientific theories is taken as evidence for the existence of those mathematical entities.[15] \\n \\n Overview of the argument \\n Mark Colyvan presents the argument in the Stanford Encyclopedia of Philosophy in the following form:[2] \\n \\n We ought to have ontological commitment to all and only the entities that are indispensable to our best scientific theories. \\n Mathematical entities are indispensable to our best scientific theories. \\n Therefore, we ought to have ontological commitment to mathematical entities. \\n Here, an ontological commitment to an entity is a commitment to believing that that entity exists.[16] The first premise is based on two fundamental assumptions: naturalism and confirmational holism. According to naturalism, we should look to our best scientific theories to determine what we have best reason to believe exists.[17] Quine (1981a,\u2002p. 21) summarized naturalism as \"the recognition that it is within science itself, and not in some prior philosophy, that reality is to be identified and described\".[18] Confirmational holism is the view that scientific theories cannot be confirmed in isolation and must be confirmed as wholes. Therefore, according to confirmational holism, if we should believe in science, then we should believe in all of science, including any of the mathematics that is assumed by our best scientific theories.[17] The argument is mainly aimed at nominalists that are scientific realists as it attempts to justify belief in mathematical entities in a manner similar to the justification for belief in theoretical entities such as electrons or quarks; Quine held that such nominalists have a \"double standard\" with regards to ontology.[2] \\n The indispensability argument differs from other arguments for platonism because it only argues for belief in the parts of mathematics that are indispensable to science. It does not necessarily justify belief in the most abstract parts of set theory, which Quine (1998,\u2002p. 400) called \"mathematical recreation \u2026 without ontological rights\".[19] Some philosophers infer from the argument that mathematical knowledge is a posteriori because it implies mathematical truths can only be established via the empirical confirmation of scientific theories to which they are indispensable. This also indicates mathematical truths are contingent since empirically known truths are generally contingent. Such a position is controversial because it contradicts the traditional view of mathematical knowledge as a priori knowledge of necessary truths.[20]\\n Whilst Quine's original argument is an argument for platonism, indispensability arguments can also be constructed to argue for the weaker claim of sentence realism\u2014the claim that mathematical theory is objectively true. This is a weaker claim because it does not necessarily imply there are abstract mathematical objects.[21]\\n Major concepts\\n Indispensability\\n The second premise of the indispensability argument states mathematical objects are indispensable to our best scientific theories. In this context, indispensability is not the same as ineliminability because any entity can be eliminated from a theoretical system given appropriate adjustments to the other parts of the system.[22] Therefore, dispensability requires an entity is eliminable without sacrificing the attractiveness of the theory. The attractiveness of the theory can be evaluated in terms of theoretical virtues such as explanatory power, empirical adequacy and simplicity.[23] Furthermore, if an entity is dispensable to a theory, an equivalent theory can be formulated without it.[24] This is the case, for example, if each sentence in one theory is a paraphrase of a sentence in another or if the two theories predict the same empirical observations.[25]\\n \\n According to the Stanford Encyclopedia of Philosophy, one of the most influential arguments against the indispensability argument comes from Hartry Field.[26] It rejects the claim that mathematical objects are indispensable to science;[27] Field has supported this argument by reformulating or \"nominalizing\" scientific theories so they do not refer to mathematical objects.[28] As part of this project, Field has offered a reformulation of Newtonian physics in terms of the relationships between space-time points. Instead of referring to numerical distances, Field's reformulation uses relationships such as \"between\" and \"congruent\" to recover the theory without implying the existence of numbers.[29] John Burgess and Mark Balaguer have taken steps to extend this nominalizing project to areas of modern physics, including quantum mechanics.[30] Philosophers such as David Malament and Ot\u00E1vio Bueno dispute whether such reformulations are successful or even possible, particularly in the case of quantum mechanics.[31]\\n\\n Field's alternative to platonism is mathematical fictionalism, according to which mathematical theories are false because they make claims about abstract mathematical objects even though abstract objects do not exist.[32] As part of his argument against the indispensability argument, Field has tried to explain how it is possible for false mathematical statements to be used by science without making scientific predictions false.[33] His argument is based on the idea that mathematics is conservative. A mathematical theory is conservative if, when combined with a scientific theory, it does not imply anything about the physical world that the scientific theory alone would not have already.[34] This explains how it is possible for mathematics to be used by scientific theories without making the predictions of science false. In addition, Field has attempted to specify how exactly mathematics is useful in application.[26] Field thinks mathematics is useful for science because mathematical language provides a useful shorthand for talking about complex physical systems.[30]\\n \\n Another approach to denying that mathematical entities are indispensable to science is to reformulate mathematical theories themselves so they do not imply the existence of mathematical objects. Charles Chihara, Geoffrey Hellman, and Putnam have offered modal reformulations of mathematics that replace all references to mathematical objects with claims about possibilities.[30]\\n\\n Naturalism \\n The naturalism underlying the indispensability argument is a form of methodological naturalism, as opposed to metaphysical naturalism, that asserts the primacy of the scientific method for determining the truth.[35] In other words, according to Quine's naturalism, our best scientific theories are the best guide to what exists.[17] This form of naturalism rejects the idea that philosophy precedes and ultimately justifies belief in science, instead holding that science and philosophy are continuous with one another as part of a single, unified investigation into the world.[36] As such, this form of naturalism precludes the idea of a prior philosophy that can overturn the ontological commitments of science.[37] This is in contrast to alternative forms of naturalism, such as a form supported by David Armstrong that holds a principle called the Eleatic principle. According to this principle there are only causal entities and no non-causal entities.[38] Quine's naturalism claims such a principle cannot be used to overturn our best scientific theories' ontological commitment to mathematical entities because philosophical principles cannot overrule science.[39] \\n \\n I'm moved to laughter at the thought of how presumptuous it would be to reject mathematics for philosophical reasons. How would you like the job of telling the mathematicians that they must change their ways, and abjure countless errors, now that philosophy has discovered that there are no classes? Can you tell them, with a straight face, to follow philosophical argument wherever it may lead? If they challenge your credentials, will you boast of philosophy's other great discoveries: that motion is impossible, that a Being than which no greater can be conceived cannot be conceived not to exist, ... and so on, and on, ad nauseum? Not me! \\n \\n David Lewis, Parts of Classes[40] \\n Quine held his naturalism as a fundamental assumption but later philosophers have provided arguments to support it. The most common arguments in support of Quinean naturalism are track-record arguments. These are arguments that appeal to science's successful track record compared to philosophy and other disciplines.[41] David Lewis (1991) famously made such an argument in a passage from his 1991 book Parts of Classes, deriding the track record of philosophy compared to mathematics and arguing that the idea of philosophy overriding science is absurd.[42] Critics of the track record argument have argued that it goes too far, discrediting philosophical arguments and methods entirely, and contest the idea that philosophy can be uniformly judged to have had a bad track record.[43] \\n \\n Quine's naturalism has also been criticized by Penelope Maddy for contradicting mathematical practice.[44] According to the indispensability argument, mathematics is subordinated to the natural sciences in the sense that its legitimacy depends on them.[45] But Maddy (1992) argues mathematicians do not seem to believe their practice is restricted in any way by the activity of the natural sciences. For example, mathematicians' arguments over the axioms of Zermelo\u2013Fraenkel set theory do not appeal to their applications to the natural sciences. Similarly, Charles Parsons has argued that mathematical truths seem immediately obvious in a way that suggests they do not depend on the results of our best theories.[46] \\n Confirmational holism \\nConfirmational holism is the view that scientific theories and hypotheses cannot be confirmed in isolation and must be confirmed together as part of a larger cluster of theories.[47] An example of this idea provided by Michael Resnik is of the hypothesis that an observer will see oil and water separate out if they are added together because they do not mix. This hypothesis cannot be confirmed in isolation because it relies on assumptions such as the absence of any chemical that will interfere with their separation and that the eyes of the observer are functioning well enough to observe the separation.[48] Because mathematical theories are likewise assumed by scientific theories, confirmational holism implies the empirical confirmations of scientific theories also support these mathematical theories.[49] \\n According to a counterargument by Maddy (1992), the theses of naturalism and confirmational holism that make up the first premise of the indispensability argument are in tension with one another. Maddy said naturalism tells us that we should respect the methods used by scientists as the best method for uncovering the truth, but scientists do not seem to act as though we should believe in all of the entities that are indispensable to science.[50] To illustrate this point, Maddy uses the example of atomic theory; she said that despite the atom being indispensable to scientists' best theories by 1860, their reality was not universally accepted until 1913 when they were put to a direct experimental test.[51] Maddy and others such as Mary Leng also appeal to the fact that scientists use mathematical idealizations, such as assuming bodies of water to be infinitely deep, without regard for the trueness of such applications of mathematics.[52] According to Maddy, this indicates that scientists do not view the indispensable use of mathematics for science as justification for the belief in mathematics or mathematical entities. Overall, Maddy said we should side with naturalism and reject confirmational holism, meaning we do not need to believe in all of the entities that are indispensable to science.[26] \\n Another counterargument due to Elliott Sober (1993) claims that mathematical theories are not tested in the same way as scientific theories. Whilst scientific theories compete with alternatives to find which theory has the most empirical support, there are no alternatives for mathematical theory to compete with because all scientific theories share the same mathematical core. As a result, according to Sober, mathematical theories do not share the empirical support of our best scientific theories so we should reject confirmational holism.[53] \\n Since these counterarguments have been raised, a number of philosophers\u2014including Resnik, Alan Baker, Patrick Dieveney, David Liggins, Jacob Busch, and Andrea Sereni\u2014have argued that confirmational holism can be eliminated from the argument.[54] For example, Resnik (1995,\u2002p. 171) has offered a pragmatic indispensability argument that \"claims that the justification for doing science ... also justifies our accepting as true such mathematics as science uses\".[55] \\n Ontological commitment \\n Another key part of the argument is the concept of ontological commitment. To say that we should have an ontological commitment to an entity means we should believe that entity exists. Quine believed that we should have ontological commitment to all the entities to which our best scientific theories are themselves committed.[56] According to Quine's \"criterion of ontological commitment\", the commitments of a theory can be found by translating or \"regimenting\" the theory from ordinary language into first-order logic. This criterion says that the ontological commitments of the theory are all of the objects over which the regimented theory quantifies; the existential quantifier for Quine was the natural equivalent of the ordinary language term \"there is\", which he believed obviously carries ontological commitment.[57] Quine thought it is important to translate our best scientific theories into first-order logic because ordinary language is ambiguous, whereas logic can make the commitments of a theory more precise. Translating theories to first-order logic also has advantages over translating them to higher-order logics such as second-order logic. Whilst second-order logic has the same expressive power as first-order logic, it lacks some of the technical strengths of first-order logic such as completeness and compactness. Second-order logic also allows quantification over properties like \"redness\", but whether we have ontological commitment to properties is controversial.[16] According to Quine, such quantification is simply ungrammatical.[58 \\n Jody Azzouni has objected to Quine's criterion of ontological commitment, saying that the existential quantifier in first-order logic need not be interpreted as always carrying ontological commitment.[59] According to Azzouni, the ordinary language equivalent of existential quantification \"there is\" is often used in sentences without implying ontological commitment. In particular, Azzouni (2004,\u2002pp. 68\u201369) points to the use of \"there is\" when referring to fictional objects in sentences such as \"there are fictional detectives who are admired by some real detectives\".[60] According to Azzouni, for us to have ontological commitment to an entity, we must have the right level of epistemic access to it. This means, for example, that it must overcome some epistemic burdens for us to be able to postulate it. But according to Azzouni (2004,\u2002p. 127), mathematical entities are \"mere posits\" that can be postulated by anyone at any time by \"simply writing down a set of axioms\", so we do not need to treat them as real.[61] \\n More modern presentations of the argument do not necessarily accept Quine's criterion of ontological commitment and may allow for ontological commitments to be directly determined from ordinary language.[62][d] \\n\\n Mathematical explanation \\n In his counterargument, Joseph Melia (1998,\u2002pp. 70\u201371) argues that the role of mathematics in science is not genuinely explanatory and is solely used to \"make more things sayable about concrete objects\".[64] He appeals to a practice he calls weaseling, which occurs when a person makes a statement and then later withdraws something implied by that statement. An example of weaseling is the statement: \"Everyone who came to the seminar had a handout. But the person who came in late didn't get one.\"[65] Whilst this statement can be interpreted as being self-contradictory, it is more charitable to interpret it as coherently making the claim: \"Except for the person who came in late, everyone who came to the seminar had a handout.\"[65] Melia said a similar situation occurs in scientists' use of statements that imply the existence of mathematical objects. According to Melia (2000,\u2002p. 489), whilst scientists use statements that imply the existence of mathematics in their theories, \"almost all scientists ... deny that there are such things as mathematical objects\".[65] As in the seminar-handout example, Melia said it is most charitable to interpret scientists not as contradicting themselves, but rather as weaseling away their commitment to mathematical objects. According to Melia, because this weaseling is not a genuinely explanatory use of mathematical language, it is acceptable to not believe in the mathematical objects that scientists weasel away.[64] \\n\\n Inspired by Maddy's and Sober's arguments against confirmational holism,[66] as well as Melia's argument that we can suspend belief in mathematics if it does not play a genuinely explanatory role in science,[67] Colyvan and Baker have defended an explanatory version of the argument.[68][e] This version of the argument attempts to remove the reliance on confirmational holism by replacing it with an inference to the best explanation. It states we are justified in believing in mathematical objects because they appear in our best scientific explanations, not because they inherit the empirical support of our best theories.[71] It is presented by the Internet Encyclopedia of Philosophy in the following form:[68] \\n \\n There are genuinely mathematical explanations of empirical phenomena.\\n We ought to be committed to the theoretical posits in such explanations.\\n Therefore, we ought to be committed to the entities postulated by the mathematics in question.\\n Number line with multiples of 3 and 4 highlighted up to the number 12. An illustration of a cicada sits at the number 13.\\n Number line visualizing why prime-numbered life cycles are advantageous compared to non-prime life cycles. If predators have life cycles of 3 or 4 years, they quickly synchronize with a non-prime life cycle such as a life cycle of 12 years. But they will not synchronize with a 13-year periodical cicada's life cycle until 39 and 52 years have passed, respectively.\\n An example of mathematics' explanatory indispensability presented by Baker (2005) is the periodic cicada, a type of insect that has life cycles of 13 or 17 years. It is hypothesized that this is an evolutionary advantage because 13 and 17 are prime numbers. Because prime numbers have no non-trivial factors, this means it is less likely predators can synchronize with the cicadas' life cycles. Baker said that this is an explanation in which mathematics, specifically number theory, plays a key role in explaining an empirical phenomenon.[72] Other important examples are explanations of the hexagonal structure of bee honeycombs, the existence of antipodes on the Earth's surface that have identical temperature and pressure, the connection between Minkowski space and Lorentz contraction, and the impossibility of crossing all seven bridges of K\u00F6nigsberg only once in a walk across the city.[73] The main response to this form of the argument, which philosophers such as Melia, Chris Daly, Simon Langford, and Juha Saatsi adopted, is to deny there are genuinely mathematical explanations of empirical phenomena, instead framing the role of mathematics as representational or indexical.[74]\r\n", 15512, 1.2, 0.9, 700],], inputs=[prompt, max_new_tokens, temperature, top_p, top_k]) output = gr.Textbox(label='Generated Text', lines=10) with gr.Row(): submit_button = gr.Button('Generate') submit_button.click( fn=generate, inputs=[prompt, max_new_tokens, temperature, top_p, top_k], outputs=output ) demo.queue(max_size=5).launch(show_api=True)